выравнивание по центру в RelativeLayout - PullRequest
0 голосов
/ 01 ноября 2011

enter image description here

есть ли способ центрировать текст под каждой картинкой?Я жестко запрограммировал его для домашних заданий, но, как видите, длина может варьироваться!Я использую Относительный макет и textView ниже каждого изображения?

Ответы [ 3 ]

1 голос
/ 01 ноября 2011

Используя комбинацию линейных макетов, вы можете достичь чего-то подобного

<LinearLayout android:layout_width="fill_parent" 
    android:layout_height="fill_parent"
    android:orientation="vertical"    
    xmlns:android="http://schemas.android.com/apk/res/android">
    <LinearLayout android:layout_width="fill_parent" 
        android:layout_height="0dip"
        android:layout_weight="1.0" android:gravity="center_vertical">
        <LinearLayout android:layout_width="0dip" 
            android:layout_height="wrap_content"
            android:orientation="vertical" 
            android:layout_weight="1.0" android:gravity="center">
            <ImageView android:layout_width="wrap_content" 
                android:layout_height="wrap_content"
                android:src="@drawable/icon"/>
            <TextView android:layout_width="fill_parent" 
                android:layout_height="wrap_content"
                android:text="Test" android:gravity="center"/>
        </LinearLayout>
        <LinearLayout android:layout_width="0dip" 
            android:layout_height="wrap_content"
            android:orientation="vertical" android:layout_weight="1.0" 
            android:gravity="center">
            <ImageView android:layout_width="wrap_content"                   
                android:layout_height="wrap_content"
                android:src="@drawable/icon"/>
            <TextView android:layout_width="fill_parent" 
                android:layout_height="wrap_content"
                android:text="Test" android:gravity="center"/>
        </LinearLayout>
    </LinearLayout>
    <LinearLayout android:layout_width="fill_parent" 
        android:layout_height="0dip"
        android:layout_weight="1.0" android:gravity="center_vertical">
        <LinearLayout android:layout_width="0dip" 
            android:layout_height="wrap_content"
            android:orientation="vertical" 
            android:layout_weight="1.0" android:gravity="center">
            <ImageView android:layout_width="wrap_content" 
                android:layout_height="wrap_content"
                android:src="@drawable/icon"/>
            <TextView android:layout_width="fill_parent" 
                android:layout_height="wrap_content"
                android:text="Test" android:gravity="center"/>
        </LinearLayout>
        <LinearLayout android:layout_width="0dip" 
            android:layout_height="wrap_content"
            android:orientation="vertical" android:layout_weight="1.0" 
            android:gravity="center">
            <ImageView android:layout_width="wrap_content"                   
                android:layout_height="wrap_content"
                android:src="@drawable/icon"/>
            <TextView android:layout_width="fill_parent" 
                android:layout_height="wrap_content"
                android:text="Test" android:gravity="center"/>
        </LinearLayout>
    </LinearLayout>
</LinearLayout>

Но я настоятельно рекомендую проверить сообщение, которое я отправляю в качестве комментария.Используется макет приборной панели.

0 голосов
/ 01 ноября 2011

было очень тяжело пройтись по вашему XML-файлу ... почему бы вам не использовать сетку, и для каждого просмотра у вас может быть изображение и текст ниже ... так намного проще ...

0 голосов
/ 01 ноября 2011
<?xml version="1.0" encoding="utf-8"?>

<ImageView android:id="@+id/imgLecture" android:src="@drawable/icon3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/textView1" android:layout_alignParentLeft="true" android:layout_marginTop="30dp" android:layout_marginLeft="60dp"></ImageView>
<ImageView android:id="@+id/imgMail" android:src="@drawable/icon4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/textView2" android:layout_alignParentRight="true" android:layout_marginTop="30dp" android:layout_marginRight="60dp"></ImageView>
  <TextView android:text="Lectures" android:id="@+id/textView3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="18sp" android:layout_below="@+id/imgLecture" android:layout_alignParentLeft="true" android:layout_marginLeft="60dp" android:layout_marginTop="2dp" ></TextView>
<TextView android:text="Mail" android:id="@+id/textView4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="18sp" android:layout_below="@+id/imgMail" android:layout_alignParentRight="true" android:layout_marginRight="60dp" android:layout_marginTop="2dp" ></TextView>

 <ImageView android:id="@+id/imgExam" android:src="@drawable/icon5" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/textView3" android:layout_alignParentLeft="true" android:layout_marginTop="30dp" android:layout_marginLeft="60dp"></ImageView>
<ImageView android:id="@+id/imgGrade" android:src="@drawable/icon6" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/textView4" android:layout_alignParentRight="true" android:layout_marginTop="30dp" android:layout_marginRight="60dp"></ImageView>
  <TextView android:text="Exams" android:id="@+id/textView5" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="18sp" android:layout_below="@+id/imgExam" android:layout_alignParentLeft="true" android:layout_marginLeft="60dp" android:layout_marginTop="2dp" ></TextView>
<TextView android:text="Grades" android:id="@+id/textView6" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="18sp" android:layout_below="@+id/imgGrade" android:layout_alignParentRight="true" android:layout_marginRight="60dp" android:layout_marginTop="2dp" ></TextView>

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...