0

下の図は、私が探しているリストビューの行です。その種類の在庫リスト。

ここに画像の説明を入力

質問:

この種のリストビュー行を描画/作成するにはどうすればよいですか?

1) 最初の列には水平線がありません。または垂直。スプリッターライン。

2) 2 番目の列は、両方の horz を持つボックスのようなものです。および vert スプリッター ライン。

2 列目と 3 列目の間にスペースがあります。

3) 3 番目の列は、テキストと小さなアイコンを含む標準のリスト ビュー行です。

3つすべてを組み合わせて、これをジャジーな行にする方法は? :)

3列目だけでリストビューを作成する方法を知っています。テキストと画像で。しかし、列の間隔と縦線は私が知らないものです。

ご提案ありがとうございます

ジェイコブ

4

2 に答える 2

2

の行レイアウトとして示されているようなレイアウトを作成するのはそれほど難しいことではありません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」) を考え出すことができると思います。

それでも不明な点がある場合は、お問い合わせください。:)

于 2012-06-03T02:02:20.537 に答える
0

TableLayoutとTableRowを使用して同様のものを作成しました。XMLで「行テンプレート」を作成し、必要に応じて任意の順序で実装できます。

アクティビティでレイアウトmain.xmlを使用しているとします。

setContentView(R.layout.main);

次に、必要に応じて各行テンプレートを膨らませます。

     LayoutInflater myInflate = (LayoutInflater)getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
     row1 = (TableRow) myInflate.inflate(R.layout.matchesoverviewlistitem, null);

     // Here you can do anything you want with the table row elements
     tv = (TextView)row1.findViewById(R.id.matchesOverLabel);
     tv.setText("MyText");

     row1.setTag(n);
     row1.setOnClickListener(seriesListener);

     // Finally add the table row to the tableLayout
     myTable.addView(row1,new TableLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));

これは、複数の行に異なるレイアウトを使用する場合にうまく機能しました。

于 2012-06-03T01:06:01.227 に答える