2011-12-21 2 views
2

Я хочу сделать макет так:Использование RelativeLayout

enter image description here

Проблема с выравнивая TextViews: Я хочу, чтобы они оба центрируется по горизонтали. Единственное, что у меня есть, - это использовать вложенный LinearLayout внутри root RelativeLayout. Ho do I center TextViews горизонтально , используя только корень RelativeLayout, без вложенных LinearLayout?

+0

Можете ли вы разместить свой xml? Если вы не слишком уверены в использовании макетов, упомянутых здесь, я могу предложить вам установить горизонтальную линейную компоновку внутри вертикальной линейной компоновки. – Ghost

ответ

1

ПОЖАЛУЙСТА ПОПРОБУЙТЕ ЭТО:

Обновление:

<?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:id="@+id/asdww" 
    android:background="#000000"> 
    <TextView android:layout_width="wrap_content" android:id="@+id/textView1" 
     android:layout_height="wrap_content" android:text="TextView" 
     android:layout_centerHorizontal="true" android:layout_marginTop="60dp" /> 
    <TextView android:layout_width="wrap_content" android:id="@+id/textView2" 
     android:layout_height="wrap_content" android:text="new aaaaaa" 
     android:layout_alignParentLeft="true" android:layout_centerHorizontal="true" 
     android:layout_marginTop="60dp" android:layout_below="@+id/textView1" 
     android:layout_marginLeft="50dp" 

     /> 


    <TextView android:layout_width="wrap_content" android:id="@+id/textView3" 
     android:layout_height="wrap_content" android:text="new aaaaaa" 
     android:layout_alignParentRight="true" 
     android:layout_centerHorizontal="true" android:layout_marginTop="60dp" 
     android:layout_below="@+id/textView1" 
     android:layout_marginRight="50dp" 

     /> 

</RelativeLayout> 
+0

Просмотров будут по-прежнему центрироваться справа и слева, но не в центре. –

+0

У меня есть обновление, пожалуйста, покажите это –

+0

Спасибо за ваши ответы, но я хотел знать, можно ли сделать это без ограничений. –

1

В вашем LinearLayout

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent"> 

    <TextView 
    android:id="@+id/tv1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"/> 

    <TextView 
    android:id="@+id/tv2" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"/>  

</LinearLayout> 

The TextViews должен быть сосредоточены сами Thats моего знания. Вы можете осуществить android:layout_marginLeft

4

Скажем, id 0f imageview - изображение. Тогда для 1-го textView вы можете сделать что-то вроде этого:

android:layout_alignLeft="@id/image" 

и для 2-го textView,

android:layout_alignRight="@id/image" 

Вы также можете дать некоторый запас в обоих textViews после этой

Смежные вопросы