[英]How to set the align parent right attribute of TextViews in relative layout programmatically
[英]How to set the width of a layout in android that extends to a point relative to the right border?
我有一个listview,左边有一个小而长的textview(两者都有不同的文本),而最右边是imageview。 问题是,当长文本视图变得太长时,它将在包装到第二行之前压缩右边的图像视图。 由于两个textview的每一行都有不同的长度,因此我无法为其长度设置一个固定的dp值。 我怎么办imageview没有被压缩?
PS:我像这样在listview中创建行:
<TextView
android:id="@+id/info"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="10sp"
android:layout_gravity="center_vertical"/>
<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="12sp"
android:layout_gravity="center_vertical"/>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
android:id="@+id/image"
android:layout_width="45dp"
android:layout_height="45dp"
android:layout_alignParentRight="true"
android:focusable="false"/>
</RelativeLayout>
将android:toLeftOf =“ @ + id / image”添加到您的TextViews。 您可能需要将TextViews的layout_width设置为fill_parent。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="@+id/info"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="10sp"
android:toLeftOf="@+id/image"
android:layout_gravity="center_vertical"/>
<TextView
android:id="@+id/text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="12sp"
android:toLeftOf="@+id/image"
android:layout_gravity="center_vertical"/>
<ImageView
android:id="@+id/image"
android:layout_width="45dp"
android:layout_height="45dp"
android:layout_alignParentRight="true"
android:focusable="false"/>
</RelativeLayout>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.