列表项的布局:
<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>
如何使文本视图的高度与按钮高度相同?并且文本视图中的文本不居中。任何想法如何集中它?
答案 0 :(得分:3)
将这些属性添加到textView
android:layout_alignBottom="@+id/removeButton"
android:layout_alignTop="@+id/removeButton"
android:gravity="center_vertical"
答案 1 :(得分: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>
答案 2 :(得分: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>
答案 3 :(得分: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>
答案 4 :(得分: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