2011-11-27 83 views
2

我有一个布局问题。奇怪的是,我无法在网上找到解决方案。也许这里有人想帮我? 我想显示一个这样的名单:Android:列表元素,固定布局

enter image description here

但所有我能得到的是这样的:

enter image description here

这里是我的列表项的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> 

我会感谢您的帮助,谢谢;)

回答

5

在上面的代码中使用RelativeLayout非线性布局,因为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> 
+0

它的工作,谢谢! 我接受这个答案,如果你做@ 87element说的话);) – Moyshe