Подтвердить что ты не робот

Как центрировать текстовое изображение внутри линейного расписания

У меня есть следующий макет, который я хотел бы сделать, чтобы текст отображался в центре и середине представления. Как я могу это понять?

Я пробовал настраивать различные атрибуты тяжести при просмотре макета в графическом представлении, но ничто не меняет его. Я бы хотел, чтобы текстовое изображение в центре, которое я сделал, но на полпути вниз.

спасибо матовому.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="@drawable/carefreebgscaledalphajpg" >



    <TextView
        android:id="@+id/textviewdatefornocallspage"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="You have no calls for "
        android:textSize="25sp" />

</LinearLayout>
4b9b3361

Ответ 1

установите значение силы тяжести в свой тег linearLayout:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
     android:gravity="center"
    android:background="@drawable/carefreebgscaledalphajpg" >

или используйте RelativeLayout следующим образом:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/carefreebgscaledalphajpg" >



    <TextView
        android:id="@+id/textviewdatefornocallspage"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:text="You have no calls for "
        android:textSize="25sp" />

</RelativeLayout>

Ответ 2

Установите android:gravity="center" в линейном макете и сохраните высоту и ширину текста как wrap_content.

Это решение работало для меня.

Ответ 3

Попробуйте

Просто я попытался ответить многим, но все ответы не работают...... наконец, эти методы работают для меня

                     <LinearLayout
                        android:layout_below="@+id/iv_divider"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:orientation="vertical"
                        android:layout_marginTop="@dimen/_10dp">
                        <TextView
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:text="@string/mycredits"
                            android:textColor="@color/colorGray"
                            android:gravity="center"
                            android:textSize="@dimen/_25dp" />
                    </LinearLayout>

Ответ 4

    <TextView
...
    android:layout_gravity="center"
....
/>

Ответ 5

Если в вертикальной вертикальной ориентации вы можете поместить текст в "горизонтальный центр" на android:layout_gravity="center". Для центрирования текстового изображения по вертикали вам необходимо установить layout_height textview в match_parent и установить android: gravity to "center". Если вы хотите использовать более одного вида в этом макете, вы должны использовать RelativeLayout и установить       android:layout_centerInParent="true".

Ответ 6

Добавьте android:gravity="center_horizontal" в LinearLayout и измените TextView layout_width как android:layout_width="wrap_content"

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:gravity="center_horizontal"
    android:background="@drawable/carefreebgscaledalphajpg" >



    <TextView
        android:id="@+id/textviewdatefornocallspage"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="You have no calls for "
        android:textSize="25sp" />

</LinearLayout>

Ответ 7

установите ширину текста в wrap_content вашего текстового поля и установите для LinearLayout значение android:gravity=center_horizontal

Ответ 8

Похоже, вы хотите android:layout_gravity для TextView

см. документы: developer.android.com

Ответ 9

установить android:gravity="center" в вашей линейной компоновке

Ответ 10

Ни один из других ответов не работал для меня. Я должен был использовать android:textAlignment="center"

Мои макеты были следующими

<LinearLayout...
    <RelativeLayout...
        <RelativeLayout....
            <TextView
                android:layout_centerInParent="true"
                android:textAlignment="center"

Ответ 11

Используйте Relative Layout, он всегда дает более точный и гибкий макет

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<ImageView
    android:id="@+id/imageView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true"
    android:src="@drawable/ic_launcher" />
</RelativeLayout>