我应该为这个listview项目布局使用什么android布局?

时间:2013-08-20 22:10:30

标签: android android-layout android-listview

我正在尝试为listview项目定义布局,看起来像附加图像(在Photoshop中制作)。我应该使用哪些布局? enter image description here

4 个答案:

答案 0 :(得分:1)

我首先提出LinearLayout水平orientation,并在RelativeLayout内提出使用属性从左/上到右/下放置其他视图:layout_alignParentTop,{ {1}},layout_alignParentBottomlayout_alignParentLeft等...

答案 1 :(得分:1)

我建议使用RelativeLayout。否则,你可能会有太多的嵌套。我不打算编写布局,但您应该查看RelativeLayout Docs并查看可以提供的所有可能属性Views。你也可能最终得到了孩子LinearLayout,这没关系。但我会使用RelativeLayout作为父母。

如果你尚未决定,那么做的好事就是在xml中快速绘制出来,你认为每个人可能会看到ViewGroup看起来最有效率。有时很难说,直到你通过编写xml代码或至少一些伪代码来进行它。

答案 2 :(得分:1)

你现在只需要使用填充和边距来玩。

Result

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

答案 3 :(得分:-1)

您可以嵌套多个不同方向的LinearLayouts来实现此目的。