0

我尝试使用四列创建自定义列表视图。 喜欢这个自定义列表视图项目

enter image description here

这里我的代码

<?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="match_parent" 

android:orientation="horizontal" > 

<LinearLayout 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" > 

<TextView 
    android:id="@+id/viewchalan" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="5555" 
    android:paddingLeft="10dip" 
    /> 

<TextView 
    android:id="@+id/viewdate" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="5555" 
    android:paddingLeft="20dip" 

    /> 

<TextView 
    android:id="@+id/viewstatus" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="555" 
    android:paddingLeft="20dip" 
    /> 
</LinearLayout> 

<Button 
    android:id="@+id/viewdetail" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
     android:layout_alignParentRight="true" 
    android:text="Button" /> 

</RelativeLayout> 

出把文件..

enter image description here 但在我的自定义列表视图项时challan数量是不同的,那么所有的数据移动。

Plz帮助我我是新的android,我不知道我该如何解决这个问题。

提前致谢

任何帮助被赞赏。

+0

你可以发布您的输出的屏幕截图? –

+0

1)你的'LinearLayout'没有'orientation'设置。 2)'RelativeLayout'是毫无意义的。 –

+0

如何在相对布局中设置android:orientation =“horizo​​ntal”?嗯惊人 –

回答

0

你可以试试这个布局:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal" > 

    <TextView 
     android:id="@+id/viewchalan" 
     android:layout_width="0dp" 
     android:layout_weight="1" 
     android:layout_height="wrap_content" 
     android:text="5555" /> 

    <TextView 
     android:id="@+id/viewdate" 
     android:layout_width="0dp" 
     android:layout_weight="1" 
     android:layout_height="wrap_content" 
     android:text="5555" /> 

    <TextView 
     android:id="@+id/viewstatus" 
     android:layout_width="0dp" 
     android:layout_weight="1" 
     android:layout_height="wrap_content" 
     android:text="555" /> 

    <Button 
    android:id="@+id/viewdetail" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Button" /> 

</LinearLayout> 
+0

非常感谢你节省了我很多时间 – Kuldeep

+0

你是最受欢迎的kuldeep。 –

1

尝试将宽度设置为零,并使用layout_weight使每个条目具有相同的宽度,以便它们排成好列。另外,将容器的LinearLayout宽度设置为match_parent。例如:

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal" > 

    <TextView 
     android:id="@+id/viewchalan" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:text="5555" 
     android:paddingLeft="10dip" 
     /> 

    ... 

</LinearLayout> 

为所有项目设置layout_width和layout_weight。

+0

我设置,但文本查看所有文本有不同的数字,然后出来并没有显示完美 – Kuldeep

0

将您的值放在TableLayout中。这正是TableLayout的用途。

+0

感谢重播,但在桌面视图我怎么可以设置列表 – Kuldeep

+0

在TableLayout下添加一个TableRow。在TableRow中,每个子View都成为一列。我通常为每个列添加一个垂直方向的LinearLayout,然后将列布局放在每个列中。 这里是一个很好的教程:http://androidexample.com/Table_Layout_-_Android_Example/index.php?view=article_discription&aid=74&aaid=98 –