2014-12-20 6 views
-1

Я создаю такой интерфейс, я хочу помочь макету розовой области. Это результат, который я хочу. http://i.imgur.com/MnkuZGZ.pnВыравнивать центр Текстовое изображение в LinearLayout

Я пробовал, но не успел. Вот мой код:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context="com.kilobolt.robotgame.MainActivity" > 

    <LinearLayout 
     android:id="@+id/layout1" 
     android:layout_width="match_parent" 
     android:layout_height="49dp" 
     android:orientation="horizontal" 
     android:background="@color/Heading"> 

     <ImageButton 
      android:id="@+id/prevMonth" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center" 
      android:gravity="center" 
      android:src="@drawable/PrevMonth" /> 

     <TextView 
      android:id="@+id/txtShowDay" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="@string/sample_date" 
      android:textColor="@color/White" 
      android:textSize="14sp" 
      android:layout_gravity="center" 
      android:gravity="center" /> 

    </LinearLayout> 

    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:text="@string/welcome_nam" 
     android:gravity="center_vertical|center" /> 

</RelativeLayout> 

А вот интерфейс после этого:

enter image description here

+1

пытаются использовать отдельный линейный макет для TextView и сделать это линейный центр макета будет работать –

+0

большое спасибо ... – user3331563

ответ

0

Используйте это с весом собственности в LinearLayout.

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

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="60dp" > 

    <ImageButton 
     android:id="@+id/imageButton1" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="2" 
     android:layout_gravity="center" 
     android:src="@drawable/ic_launcher" /> 

    <TextView 
     android:id="@+id/textView1" 
     android:layout_width="0dp" 
     android:layout_weight="6" 
     android:gravity="center" 
     android:layout_gravity="center" 
     android:layout_height="wrap_content" 
     android:text="TextView" /> 

    <ImageButton 
     android:id="@+id/imageButton2" 
     android:layout_weight="2" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center" 
     android:src="@drawable/ic_launcher" /> 
</LinearLayout> 

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