Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/193.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
此listview项目布局应使用什么android布局?_Android_Android Layout_Android Listview - Fatal编程技术网

此listview项目布局应使用什么android布局?

此listview项目布局应使用什么android布局?,android,android-layout,android-listview,Android,Android Layout,Android Listview,我正在尝试定义listview项目的布局,它看起来像附加的图像(在Photoshop中制作)。我应该使用什么布局? 您可以嵌套多个具有不同方向的线性布局以实现此目的。我建议首先使用具有水平方向的线性布局,然后在相对布局内,使用属性从左/上到右/下放置其他视图:布局\u alignParentTop,layout\u-alignParentBottom,layout\u-alignParentLeft,layout\u-alignParentRight等等……我建议使用RelativeLayout

我正在尝试定义listview项目的布局,它看起来像附加的图像(在Photoshop中制作)。我应该使用什么布局?

您可以嵌套多个具有不同方向的线性布局以实现此目的。

我建议首先使用具有水平方向的
线性布局
,然后在
相对布局
内,使用属性从左/上到右/下放置其他视图:
布局\u alignParentTop
layout\u-alignParentBottom
layout\u-alignParentLeft
layout\u-alignParentRight
等等……

我建议使用
RelativeLayout
。否则,可能会导致嵌套过多。我不打算编写布局,但您应该查看,并查看可以提供
视图的所有可能属性。您可能也会得到child
LinearLayout
s,这没关系。但是我会使用
RelativeLayout
作为父对象


如果您还没有决定,一件好事情是用xml快速地将它画出来,您认为每个人使用
ViewGroup查看的方式似乎是最有效的。有时候很难说,直到你开始写xml代码或者至少是一些伪代码。你现在只需要使用填充和边距

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

    <LinearLayout 
            android:id="@+id/gray_layout"
            android:layout_width="40dp"
            android:layout_height="match_parent"
            android:orientation="vertical"
            android:background="#888888"
            android:layout_alignParentLeft="true"
            android:gravity="center_vertical">

        <TextView android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="AUG"/>

        <TextView android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="18"/>

        <TextView android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="2011"/>

    </LinearLayout>

    <View 
        android:id="@+id/divider"
        android:layout_width="match_parent"
        android:layout_height="2dp"
        android:background="#000088"
        android:layout_toRightOf="@id/gray_layout"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:layout_marginTop="30dp"/>

    <TextView android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@id/divider"
        android:text="Title"
        android:layout_marginBottom="5dp"
        android:layout_alignBottom="@id/divider"/>

    <TextView android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignRight="@id/divider"
        android:text="18. aug 23:49"
        android:layout_marginBottom="5dp"
        android:layout_alignBottom="@id/divider"/>

    <TextView android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@id/divider"
        android:text="Short msg"
        android:layout_marginTop="10dp"
        android:layout_alignTop="@id/divider"/>

    <ImageView 
        android:id="@+id/info_button"
        android:layout_width="40dp"
        android:layout_height="40dp"
        android:layout_alignParentRight="true"
        android:layout_alignParentBottom="true" 
        android:background="#ff0000"/>

    <ImageView 
        android:id="@+id/arrow_button"
        android:layout_width="40dp"
        android:layout_height="40dp"
        android:layout_above="@id/info_button"
        android:layout_toLeftOf="@id/info_button"
        android:background="#00ff00"/>

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"        
        android:layout_above="@id/arrow_button"
        android:layout_toLeftOf="@id/info_button"
        android:layout_alignLeft="@id/arrow_button"
        android:gravity="center_horizontal"
        android:text="30" />

</RelativeLayout>



如果你想把所有带有白色背景的东西都放在
RelativeLayout
中,我可以买这个。我仍然认为,
LinearLayout
可能没有必要,但这只是我的观点,如果不这样做,很难说。回答得好。
LinearLayout
将包含两个块:白色背景和其余视图。水平方向有助于保持水平和对齐。白色背景可以是一个简单的
文本视图
。剩下的视图将在
RelativeLayout
中,您可以在这里使用所提到的属性。请将帮助您解决问题的人标记为已解决。我正在努力,但没有一个答案完全解决了我的问题。我发现很难按照你的建议调整填充和边距。我改用GridLayout,差不多完成了。稍后我会发布代码。GridLayout对此似乎有点复杂,但祝你好运;)嗯,调整填充更难。至少对我来说。告诉我哪些是有问题的填充物和我的解决方案,我会尽力帮助。