6

ListActivity は BaseAdapter の拡張機能と次のレイアウトを使用します。

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

<ListView android:id="@android:id/list" android:layout_width="fill_parent"
    android:layout_height="fill_parent" android:drawSelectorOnTop="false"
    android:divider="@drawable/divider"
    android:dividerHeight="2dip" android:clickable="true"
    android:choiceMode="singleChoice"    
    android:cacheColorHint="@color/application_background_color">
</ListView>

   </LinearLayout>

行の次のレイアウトをインフレートします。

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

    <TextView android:id="@+id/Row" 
        android:layout_width="fill_parent" android:layout_height="50dip"
        android:textSize="20dip" android:textColor="#000000"
        android:layout_margin="8dip"
        android:gravity="center_vertical"></TextView>

    </LinearLayout>   

drawable/divider.xml は現時点では次のようになっていますが、さまざまな種類をすべて試しました。

    <shape xmlns:android="http://schemas.android.com/apk/res/android"
        android:shape="line">
      <stroke android:color="#FF000000">
      </stroke>
    </shape>    

画像からドローアブルを読み取ると、機能します。ドローアブルを .xml ファイルとして定義すると機能しないのはなぜですか?

更新:
コードは、Android 開発者の例の EfficientAdapter と同じパターンに従っています:
http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/view/List14.html

4

2 に答える 2

2

以下のコードは私のために働きます:

リストのレイアウト:

<ListView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/list"
    android:cacheColorHint="@android:color/transparent"
    android:background="@android:color/transparent"
    android:textFilterEnabled="false"
    style="@style/ListDivider"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">
</ListView>

スタイル.xml

<resources>
    <style name="ListDivider">
        <item name="android:divider">@drawable/my_shape</item>
        <item name="android:dividerHeight">5dp</item>
    </style>
</resources>

私の形:

    <shape
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:shape="rectangle">
        <padding
            android:top="2dp"
            android:left="2dp"
            android:right="2dp"
            android:bottom="2dp" />
        <corners
            android:radius="5dp" />
        <solid
            android:color="@android:color/white" />
    </shape>
于 2011-07-19T14:26:54.527 に答える
0

破線の仕切りの私の回避策は次のとおりです。

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:top="1dip">
        <shape android:shape="rectangle" >
            <solid android:color="#FF123243" />

            <stroke
                android:dashGap="5dp"
                android:dashWidth="8dp"
                android:width="1dp"
                android:color="#FFFFFFFF" />
        </shape>
    </item>
    <item>
        <shape android:shape="rectangle" >
            <solid android:color="#FF000000" />
        </shape>
    </item>
</layer-list>

2 番目の図形の色をリストの背景と仕切りの高さと "同期" してください。

于 2012-04-13T18:54:18.670 に答える