2016-04-04 5 views
0

Как разместить два текстовых вида Marked within red rectangle в относительных макетах с выравниванием по центру. Как я могу конструировать как показано в изображении? Здесь текст и номер являются текстовыми.Как центрировать два текстовых вида по центру в относительном макете

enter image description here

Я попытался следующие, но я не мог получить центр выровненный вид относительного расположения.

 <RelativeLayout 
      android:layout_width="fill_parent" 
      android:layout_height="50dp"> 

      <LinearLayout 
       android:id="@+id/location_party_size_lbl_layer" 
       android:layout_width="wrap_content" 
       android:layout_height="match_parent" 
       android:layout_centerInParent="true" 
       android:orientation="horizontal"> 

       <TextView 
        android:id="@+id/location_party_size_lbl" 
        android:layout_width="170dp" 
        android:layout_height="wrap_content" 
        android:layout_marginTop="10dp" 
        android:gravity="center_horizontal" 
        android:maxLines="2" 
        android:text="@string/loc_estimate" 
        android:textColor="@android:color/white" 
        android:textSize="15sp" /> 
      </LinearLayout> 

      <LinearLayout 
       android:layout_width="fill_parent" 
       android:layout_height="match_parent" 
       android:layout_centerVertical="true" 
       android:layout_toRightOf="@+id/location_party_size_lbl_layer" 
       android:orientation="horizontal" 
       android:paddingBottom="10dp" 
       android:paddingTop="10dp" 
       android:weightSum="1.0"> 

       <TextView 
        android:id="@+id/location_party_size" 
        android:layout_width="0dp" 
        android:layout_height="match_parent" 
        android:layout_weight="0.48" 
        android:background="@drawable/rounded_bg" 
        android:gravity="center" 
        android:textColor="@android:color/white" /> 

       <TextView 
        android:id="@+id/qnowscreen_dummy_tv" 
        android:layout_width="0dp" 
        android:layout_height="match_parent" 
        android:layout_weight="0.52" 
        android:visibility="invisible" /> 
      </LinearLayout> 
     </RelativeLayout> 
+0

Возможно, вы можете использовать линейный выход с ориентацией по горизонтали и весам на своих детей? – Bram

+0

Можете ли вы указать из ваших xml-тегов, какие два текстовых поля вы хотите выровнять по центру, и если вы хотите, чтобы их центрировали по вертикали и по горизонтали, как будто у вас их два, они будут перекрываться? Как вы хотите, чтобы они располагались рядом друг с другом. Это непонятно из изображения. –

+0

@ Ms Yvette ǝʇʇǝʌʎ sW, location_party_size_lbl используется для отображения текста «оцененный ....» и location_party_size, используемый для показа «2» –

ответ

4

Вы можете сделать это путем создания вид якорь и совместив TextView сек относительно якоря.

<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <View 
     android:id="@+id/anchor" 
     android:layout_width="0dp" 
     android:layout_height="0dp" 
     android:layout_centerInParent="true" /> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_above="@id/anchor" 
     android:layout_centerHorizontal="true" /> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@id/anchor" 
     android:layout_centerHorizontal="true" /> 

    </RelativeLayout> 
+0

Он выровнен по вертикали, не выравнивается по горизонтали. –

+0

Кажется, я неправильно понял вас. К сожалению, вы не можете реализовать с помощью RelativeLayout'. – Michael

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