2014-12-20 4 views
-1

나는이 같은 인터페이스를 만들고 있는데, 나는 핑크색 영역을 배치하는 것을 돕고 싶다. 이것이 제가 원하는 결과입니다. http://i.imgur.com/MnkuZGZ.pnLinearLayout의 가운데 맞춤 Textview

시도했지만 성공하지 못했습니다. 여기 내 코드입니다 :

<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> 

그리고 여기 그 후 인터페이스 :있는 LinearLayout 체중 속성

enter image description here

+1

시도는 텍스트 뷰에 대한 별도의 선형 레이아웃을 사용하고 –

+0

많은 감사를 작동 할 선형 레이아웃 센터를 만들기 위해 ... – user3331563

답변

0

사용이.

<?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>