如何创建专辑行布局(以xml格式)?

时间:2012-06-09 11:42:26

标签: android xml android-layout

我想知道在xml:

中构造这样的行的最佳方法是什么

ListView Row

有2个ImageViews(一个用于明星,一个用于封面)和2个TextViews(一个用于“相册”,一个用于“艺术家”)。我不确定哪种布局是最好的,以及如何构造这一行。

2 个答案:

答案 0 :(得分:0)

您应该使用RelativeLayout(还有其他选项):

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

    <ImageView
        android:id="@+id/album_cover"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:src="the drawable" />

    <ImageView
        android:id="@+id/star"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:src="the drawable" />

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_toLeftOf="@id/star"
        android:layout_toRightOf="@id/album_cover"
        android:text="Album" />

    <TextView
    android:id="@+id/textView2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_toLeftOf="@id/star"
    android:layout_toRightOf="@id/album_cover"
    android:layout_below="@id/textView1"
    android:text="Artist" />

</RelativeLayout>

答案 1 :(得分:0)

使用类似的东西:

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_height="fill_parent"
    android:layout_width="fill_parent"
    android:orientation="horizontal"
    android:paddingBottom="2dip"
    android:paddingTop="2dip" >

    <ImageView
        android:id="@+id/image1"
        android:gravity="center"
        android:layout_gravity="center"
        android:layout_height="wrap_content"
        android:layout_weight="6"
        android:layout_width="fill_parent" />

    <LinearLayout
        android:orientation="vertical"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:layout_width="fill_parent" >

        <TextView
            style="@style/TextView"
            android:id="@+id/text1"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:layout_width="fill_parent"
            android:textStyle="bold" />

        <TextView
            style="@style/TextView"
            android:id="@+id/text2"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:layout_width="fill_parent" />
    </LinearLayout>

    <ImageView
        android:id="@+id/image2"
        android:gravity="center"
        android:layout_gravity="center"
        android:layout_height="wrap_content"
        android:layout_weight="6"
        android:layout_width="fill_parent" />
</LinearLayout>