の行レイアウトとして示されているようなレイアウトを作成するのはそれほど難しいことではありませんListView
。道中、少しだけお手伝いします。dimens.xml
たとえば、「正方形」のサイズをハードコーディングせずに、異なる画面密度/サイズ バケットからそれらを提供するなど、いくつかの改善を行いたい場合があることに注意してください。
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="?android:attr/listPreferredItemHeight"
android:gravity="center_vertical">
<View android:layout_width="30dp" android:layout_height="30dp"
android:layout_margin="5dp" android:background="@drawable/border_color_red" />
<TextView android:layout_width="?android:attr/listPreferredItemHeight"
android:layout_height="?android:attr/listPreferredItemHeight"
android:background="@drawable/border" android:gravity="center"
android:text="QTY" android:textAppearance="?android:attr/textAppearanceMedium" />
<RelativeLayout android:layout_width="0dp"
android:layout_height="?android:attr/listPreferredItemHeight"
android:layout_marginLeft="5dp" android:layout_marginRight="5dp"
android:layout_weight="1" android:background="@drawable/border"
android:gravity="center_vertical" android:padding="5dp">
<TextView android:id="@android:id/text1"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_centerVertical="true" android:layout_toLeftOf="@+id/star"
android:textAppearance="?android:attr/textAppearanceMedium" />
<CheckBox android:id="@+id/star" style="?android:attr/starStyle"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_centerVertical="true" android:layout_toLeftOf="@+id/box_right"
android:text=" " />
<View android:id="@+id/box_right" android:layout_width="30dp"
android:layout_height="30dp" android:layout_alignParentRight="true"
android:layout_centerVertical="true" android:layout_margin="5dp"
android:background="@drawable/border_color_red" />
</RelativeLayout>
</LinearLayout>
はListView
、その仕切りを非表示にする必要があります。
<ListView android:id="@android:id/list" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:divider="@null">
<!-- Preview: listitem=@layout/list_item_layout -->
</ListView>
ボーダーは単純な を使用して追加されShapeDrawable
ます:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<stroke android:height="1dp" android:width="1dp" android:color="#000" />
<solid android:color="@android:color/transparent" />
</shape>
色を変更solid
して、別の塗りつぶしの色を作成します (正方形など)。
結果は次のようになります。

最大の欠点は、異なる行の間にある「二重」の仕切りを取り除く簡単な方法がないことです。本当に気になる場合は、いくつかの回避策があります (たとえば、アダプターの最初と最後の項目に異なるレイアウトを作成するか、最初と最後の項目をヘッダーとフッターとして追加するか、行を要素に分割します。後で切り替えることができる個別のビューなど...)。
ImageView
それはかなり自明なので、追加しませんでした。「アイテム」と同じ位置に配置し、TextView
テキストと画像のどちらを表示するかに基づいて 2 つを切り替えます。
Adapter
レイアウトに一致するもの(および「ViewHolder」/「RowWrapper」) を考え出すことができると思います。
それでも不明な点がある場合は、お問い合わせください。:)