4

リスト項目全体を右側に描画可能なシャドウでカバーしようとしています。

問題は、ドローアブルをラップするレイアウトの高さが一定でないことです。親の上に揃えて親の下に揃えるようにドローアブルを設定するのにうんざりしましたが、それでも親レイアウトの高さ全体を引き伸ばしません。

右側の影を見てください (最小の高さのプロパティを提供して表示できるようにしました。4 番目のリスト項目は最小のビューよりも大きく、影は伸びません)

ここに画像の説明を入力

ソース:

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

    <include layout="@layout/list_item_header" />

    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >

        <ImageView
            android:id="@+id/img_news_thumb"
            android:layout_width="@dimen/listview_one_row"
            android:layout_height="@dimen/listview_one_row"
            android:scaleType="centerCrop"
            android:src="@drawable/default_news_thumb" />

        <TextView
            android:id="@+id/txt_news_title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_alignParentTop="true"
            android:layout_alignWithParentIfMissing="true"
            android:layout_marginLeft="@dimen/space_m"
            android:layout_marginTop="@dimen/space_s"
            android:layout_toRightOf="@+id/img_news_thumb"
            android:ellipsize="marquee"
            android:paddingRight="@dimen/space_m"
            android:singleLine="false"
            android:text="Title"
            android:textSize="14sp"
            android:textStyle="bold" />

        <TextView
            android:id="@+id/txt_news_date"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_alignWithParentIfMissing="true"
            android:layout_below="@+id/txt_news_title"
            android:layout_marginBottom="0dp"
            android:layout_marginLeft="@dimen/space_m"
            android:layout_marginTop="@dimen/space_s"
            android:layout_toRightOf="@+id/img_news_thumb"
            android:ellipsize="end"
            android:paddingRight="@dimen/space_m"
            android:singleLine="true"
            android:text="Date"
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:textColor="@color/font_light" />

        **<ImageView
            android:id="@+id/img_news_list_shadow"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_alignParentBottom="true"
            android:layout_alignParentRight="true"
            android:layout_alignTop="@+id/img_news_thumb"
            android:minHeight="@dimen/listview_one_row"
            android:scaleType="fitXY"
            android:src="@drawable/list_shadow_r" />**

        <ImageView
            android:id="@+id/img_selected_arrow"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_centerVertical="true"
            android:scaleType="fitXY"
            android:src="@drawable/list_item_arrow"
            android:visibility="gone" />
    </RelativeLayout>

    <include layout="@layout/list_item_devider" />

</LinearLayout>
4

2 に答える 2

1

親レイアウト、つまりこの場合の線形レイアウトは、リストビューで使用されると常にコンテンツをラップするため、不可能であることがわかりました。

于 2012-09-24T13:06:53.470 に答える
0

最近の調査により、答えはそれよりもはるかに簡単であることがわかりました。

レイアウトをインフレートするときは、これを使用する必要があります。

View rowView = inflater.inflate(R.layout.row_layout, parent, false);

一般的に使用されるエラーの代わりに:

View rowView = inflater.inflate(R.layout.row_layout, null);
于 2013-07-25T11:53:50.090 に答える