2

我想创建一个像 CyanogenMod 调用日志这样的布局,其中有一个带有几个视图的列表项,右侧有一个可点击的按钮,分别获得焦点(截图)。相反,我得到了这个烂摊子

这是我的代码:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:minHeight="?android:attr/listPreferredItemHeight"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:paddingLeft="4dip"
    >

    <DontPressWithParentImageView android:id="@+id/play_icon"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:paddingLeft="14dip"
        android:paddingRight="14dip"
        android:layout_alignParentRight="true"
        android:gravity="center_vertical"
        android:src="@drawable/sym_play"
        android:background="@drawable/play_background"
        />

    <View android:id="@+id/divider"
        android:layout_width="1px"
        android:layout_height="fill_parent"
        android:layout_marginTop="5dip"
        android:layout_marginBottom="5dip"
        android:layout_toLeftOf="@id/play_icon"
        android:layout_marginLeft="2dip"
        android:background="@drawable/divider_vertical_dark"
        />

    <TextView android:id="@+id/file_info"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_marginBottom="8dip"
        android:layout_marginTop="-10dip"
        android:layout_marginLeft="10dip"
        android:layout_alignWithParentIfMissing="true"
        android:singleLine="true"
        android:ellipsize="marquee"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:textStyle="bold"
        />

    <TextView android:id="@+id/file_title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_above="@id/file_info"
        android:layout_alignWithParentIfMissing="true"
        android:layout_marginBottom="-10dip"
        android:layout_marginLeft="4dip"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:singleLine="true"
        android:ellipsize="marquee"
        android:gravity="center_vertical"
        />
</RelativeLayout>

作为参考,我开始使用的代码在此处此处,源代码在DontPressWithParentImageView此处但正如您从我的屏幕截图中看到的那样,该部分正在工作)。

我究竟做错了什么?

4

1 回答 1

1

通过使用两个LinearLayouts 而不是 a 来解决RelativeLayout

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:paddingLeft="4dip"
    >

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

        <TextView android:id="@+id/file_title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="4dip"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:singleLine="true"
            android:ellipsize="marquee"
            android:gravity="center_vertical"
            />

        <TextView android:id="@+id/file_info"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dip"
            android:layout_marginBottom="6dip"
            android:singleLine="true"
            android:ellipsize="marquee"
            android:textAppearance="?android:attr/textAppearanceSmall"
            />
    </LinearLayout>

    <View android:id="@+id/divider"
        android:layout_width="1px"
        android:layout_height="fill_parent"
        android:layout_marginTop="5dip"
        android:layout_marginBottom="5dip"
        android:layout_marginLeft="2dip"
        android:background="@drawable/divider_vertical_dark"
        />

    <DontPressWithParentImageView
        android:id="@+id/play_icon"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:paddingLeft="10dip"
        android:paddingRight="10dip"
        android:gravity="center_vertical"
        android:src="@drawable/sym_play"
        android:background="@drawable/play_background"
        />
</LinearLayout>
于 2011-01-09T04:43:47.927 回答