2013-12-20 18 views
1

佈局列表項:的TextView相同的高度附近的按鈕

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

    <Button 
     android:id="@+id/removeButton" 
     android:layout_width="wrap_content" 
     android:layout_height="fill_parent" 
     android:layout_alignParentRight="true" 
     android:drawableRight="@drawable/ic_action_next_item" 
     android:gravity="center_horizontal"> 
    </Button> 

    <TextView 
     android:id="@+id/list_item" 
     android:layout_width="match_parent" 
     android:layout_height="fill_parent" 
     android:layout_toLeftOf="@id/removeButton" 
     android:background="#e2e2e2" 
     android:gravity="center_vertical|left" /> 

</RelativeLayout> 

我怎樣才能使文本查看相同的高度,按鈕高度?並且文本視圖內的文本不居中。任何想法如何居中?

​​

回答

3

這些屬性添加到textView

android:layout_alignBottom="@+id/removeButton" 
android:layout_alignTop="@+id/removeButton" 
android:gravity="center_vertical" 
+0

但是這工作TextView的內的文本不居中。任何想法? –

+0

將**引力** **屬性添加到**中心**爲textview –

+0

它是,但內容只是水平居中而不是垂直 –

1

試試這個:

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

    <Button 
     android:id="@+id/removeButton" 
     android:layout_width="wrap_content" 
     android:layout_height="fill_parent" 
     android:layout_alignParentRight="true" 
     android:drawableRight="@drawable/ic_action_next_item" 
     android:gravity="center_horizontal"> 
    </Button> 

    <TextView 
     android:id="@+id/list_item" 
     android:layout_width="match_parent" 
     android:layout_height="fill_parent" 
     android:layout_toLeftOf="@id/removeButton" 
     android:layout_alignBottom="@id/removeButton" 
     android:layout_alignTop="@id/removeButton" 
     android:background="#e2e2e2" 
     android:gravity="center_vertical|left" /> 

</RelativeLayout> 
0

試試這個..

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

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" > 

     <TextView 
      android:id="@+id/list_item" 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_weight="1" 
      android:background="#e2e2e2" 
      android:gravity="center" /> 

     <Button 
      android:id="@+id/removeButton" 
      android:layout_width="wrap_content" 
      android:layout_height="match_parent" 
      android:layout_alignParentRight="true" 
      android:drawableRight="@drawable/ic_action_next_item" 
      android:gravity="center_horizontal" > 
     </Button> 
    </LinearLayout> 

</LinearLayout> 

還是這個

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

    <Button 
     android:id="@+id/removeButton" 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:layout_alignParentRight="true" 
     android:drawableRight="@drawable/ic_action_next_item" 
     android:gravity="center_horizontal"> 
    </Button> 

    <TextView 
     android:id="@+id/list_item" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="#e2e2e2" 
     android:layout_toLeftOf="@+id/removeButton" 
     android:text="textview" 
     android:gravity="center" /> 

</RelativeLayout> 
0

包裝你的TextView和按鈕LinearLayout

<LinearLayout 
      android:orientation="horizontal" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content"> 


     <Button 
      android:id="@+id/removeButton" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentRight="true" 

      android:gravity="center_horizontal"> 
     </Button> 

     <EditText 
      android:id="@+id/list_item" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_toLeftOf="@id/removeButton" 
      android:background="#e2e2e2" 
      android:gravity="center_vertical|left" /> 

     </LinearLayout> 
0

裏面添加

android:layout_gravity="center" // Make the TextView control in the center of it parent Control 
android:gravity="center"  // Make text in the center of TextView control 

你的TextView