【发布时间】:2015-01-29 10:02:25
【问题描述】:
下面发布的xml布局是listView的布局,editText允许用户输入字符串,imageView是按下时可点击的图标,字符串应添加到listView.
视图相互对齐,如下图xml 所示。问题是当用户输入一个很短的字符串或很长的字符串然后单击图标将其添加到listview 时,会发生我失去CheckBox 和imageView 的对齐方式。
例如,最初listview 的对齐方式如下,其中CB 指的是CheckBox,iv 指的是Imageview,圆点表示分隔视图的空格:
topic_1..........CB..........IV
topic_2..........CB..........IV
topic_3..........CB..........IV
topic_4..........CB..........IV
topic_5..........CB..........IV
topic_6..........CB..........IV
topic_10000..........CB..........IV
t..........CB..........IV
如您所见,在“topic_10000”和“t”中,CB 和 IV 的位置都发生了位移。但我希望checkBox 和imageview 始终相互对齐,无论主题有多长。
我怎样才能做到这一点?
xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<RelativeLayout
android:id="@+id/rl1_List"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_alignParentStart="true"
android:paddingEnd="10dp"
android:paddingStart="10dp">
<TextView
android:id="@+id/tvlist_topic"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"/>
</RelativeLayout>
<RelativeLayout
android:id="@+id/rl2_List"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toEndOf="@id/rl1_List"
android:layout_centerInParent="true"
android:layout_marginStart="70dp"
android:layout_marginEnd="70dp">
<CheckBox
android:id="@+id/cbList_hook"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="false"
android:focusableInTouchMode="false"
android:checked="false"/>
</RelativeLayout>
<RelativeLayout
android:id="@+id/rl3_List"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toEndOf="@id/rl2_List"
android:layout_alignParentEnd="true"
android:layout_marginStart="30dp"
android:layout_marginEnd="30dp">
<ImageView
android:id="@+id/ivList_delete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="false"
android:focusableInTouchMode="false"
android:clickable="true"
android:src="@drawable/delete_icon"
android:contentDescription="icon to delete item from the Listview"/>
</RelativeLayout>
【问题讨论】:
标签: android android-layout android-listview android-relativelayout