如何在listview中将我的布局文本设置在彼此旁边?

时间:2013-03-31 06:29:28

标签: android android-layout android-listview

在这里,我希望我的日期旁边是razin旁边的标题,而不是标题下方的listviev。我曾经使用了listview的android deafult布局。

<?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="fill_parent"
    android:background="@drawable/myyellow">

    <ListView android:id="@+id/android:list"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"/>

</LinearLayout>

enter image description here

编辑:我根据你的建议得到了这个,但我想在角落里约会。

image

2 个答案:

答案 0 :(得分:2)

ListView项目顶级布局设为LinearLayout,并采用“水平”方向。然后TextViews将并排。

您也可以使用RelativeLayout,然后轻松将每个TextView放在任何位置。

默认ListView布局android.R.layout.simple_list_item_2如下所示:

<TwoLineListItem xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:minHeight="?android:attr/listPreferredItemHeight"
    android:mode="twoLine"
    android:paddingBottom="9dp"
    android:paddingTop="5dp" >

    <TextView
        android:id="@android:id/text1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dp"
        android:textAppearance="?android:attr/textAppearanceListItem" />

    <TextView
        android:id="@android:id/text2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@android:id/text1"
        android:layout_below="@android:id/text1"
        android:textAppearance="?android:attr/textAppearanceSmall" />

</TwoLineListItem>

从此开始。
要使用“横向”LinearLayout,您必须使用“TwoLineListItem”将LinearLayout更改为android:orientation="horizontal,然后再添加TextView
要使用RelativeLayout,您必须将TwoLineListItem更改为RelativeLayout,添加其他TextView,然后根据需要放置它们。

答案 1 :(得分:0)

这将是组件。使用Baseadapter将其添加到列表中将为您提供所需的功能。您可以使用baseadapter中的getview函数添加。这个link将帮助您

    <RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Title"
        android:textSize="45dp"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_alignParentRight="true"
        android:layout_marginRight="18dp"
        android:text="Sub content"
        android:textAppearance="?android:attr/textAppearanceMedium" />

</RelativeLayout>

enter image description here