Android:列出元素,固定布局

Moy*_*she 2 android listview listviewitem android-layout

我有布局问题.奇怪的是,我无法在网上找到解决方案.也许这里有人想帮助我?我想显示一个这样的列表:

在此输入图像描述

但我能得到的就是:

在此输入图像描述

这是我的列表项的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>
Run Code Online (Sandbox Code Playgroud)

我很感谢你的帮助,谢谢;)

Aru*_*mar 5

RelativeLayout在上面的代码中使用而不是linearlayout,因为android:layout_alignParentRight="true"只能相对于非线性布局.

<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>
Run Code Online (Sandbox Code Playgroud)