我遇到布局问题。奇怪的是,我在网上找不到解决方案。也许这里有人愿意帮助我? 我想显示一个这样的列表:
但我能得到的只是这个:
这是我的列表项的 xml 代码:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content" android:layout_height="wrap_content">
<ImageView android:id="@android:id/icon" android:layout_width="22px"
android:layout_height="22px" android:layout_marginLeft="4px"
android:layout_marginRight="10px" android:layout_marginTop="4px"
android:src="@drawable/icon" />
<TextView android:id="@android:id/text1" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_marginLeft="4px"
android:layout_marginRight="10px" android:textSize="20px" />
<TextView android:id="@android:id/text2" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_marginLeft="4px"
android:layout_marginRight="10px" android:textSize="20px"
android:layout_alignParentRight="true"
android:layout_weight="0.4" />
</LinearLayout>
非常感谢您的帮助,谢谢;)
最佳答案
在上面的代码中使用RelativeLayout
而不是线性布局,因为android:layout_alignParentRight="true"
仅适用于relativelatout而不是线性布局。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content" android:layout_height="wrap_content">
<ImageView android:id="@android:id/icon" android:layout_width="22px"
android:layout_height="22px" android:layout_marginLeft="4px"
android:layout_marginRight="10px" android:layout_marginTop="4px"
android:src="@drawable/icon" />
<TextView android:id="@android:id/text1" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_marginLeft="4px"
android:layout_marginRight="10px" android:textSize="20px" />
<TextView android:id="@android:id/text2" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_marginLeft="4px"
android:layout_marginRight="10px" android:textSize="20px"
android:layout_alignParentRight="true"
android:layout_weight="0.4"
/>
</RelativeLayout>
关于Android:列表元素,固定布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8286541/