3

こんにちはドロイド!

何時間にもわたる調査の結果、説明のつかない厄介なレイアウトの問題に直面しています... :/。ここに提示する縮小テストケースを作成しました。

私は単純なリスト項目のレイアウトを持っています。

リスト項目 http://www.freeimagehosting.net/4075a.jpg

lisアイテム画像リンク

XML:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/relativeLayout1"
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"
    android:minHeight="96dp">

<TextView android:layout_width="wrap_content"
    android:layout_height="wrap_content" 
    android:text="TextView"
    android:id="@+id/textView1" android:textAppearance="?android:attr/textAppearanceMedium"
    android:layout_centerVertical="true" android:layout_centerHorizontal="true" />

<TextView android:layout_width="wrap_content"
    android:layout_height="wrap_content" android:text="TextView"
    android:id="@+id/textView2" android:layout_alignParentTop="true" />

<ImageView 
    android:layout_width="10dp" 
    android:layout_height="match_parent"
    android:id="@+id/imageView1" 
    android:src="@drawable/errorindicator"
    android:layout_below="@id/textView2" />

</RelativeLayout>

エラー インジケータは赤い四角形で、左側の画像で確認できます。xml は次のようになります。

    <?xml version="1.0" encoding="utf-8"?>
    <shape shape="rectangle"  xmlns:android="http://schemas.android.com/apk/res/android">
     <solid android:color="@color/ControllingConflictColor" />
     <padding android:left="0dp" android:top="0dp" 
         android:right="0dp" android:bottom="0dp" />
    </shape>

説明されているリスト項目のレイアウトは期待どおりに機能します。

上記のように、リストビューにリストアイテムを入力しようとしました。結果は次のようになります。

リスト アイテムを含むリスト ビュー http://www.freeimagehosting.net/4cc4b.jpg

リストビューの画像リンク

対応するxml:

    <?xml version="1.0" encoding="utf-8"?>
    <ListView android:id="@+id/listView1" android:layout_width="fill_parent"
        android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android">
        <!-- Preview: listitem=@layout/test -->
    </ListView>

画像でわかるように、赤い四角形の高さが親と一致しなくなりました。画像はデザイナーが作成したものですが、エミュレーターやデバイスでも同様の効果が得られます。API レベル 8 向けに開発しています。

**説明されたレイアウトがリストビューで期待どおりに機能しない理由を誰かが説明してくれれば幸いです。シェイプ ドローアブルの動作が異なるのはなぜですか? **

お時間をいただきありがとうございます:)

編集: 画像の埋め込みに問題があります。代わりにリンクを使用しました。申し訳ありません;( 編集: xml-drawable タグを追加しました。

編集:私の例は、さらに簡単にすることができます。実際のレイアウトと似ているため、2 つのテキスト ビューを含めました。例から 2 つのテキスト ビューを削除できますが、レイアウトがリスト ビューで使用されている場合、イメージ ビューで描画可能な形状が、定義されている親の高さと一致しないという問題が依然として存在します。

4

3 に答える 3

0

私の望む振る舞いはgivelayoutmanagerでは不可能だと思うので、私は自分の個人的な状況に合った別の方法を選びました。

私はRelativeLayoutのonDrawメソッドをオーバーライドし、この赤い長方形を自分でペイントしました(レイアウトプロセスが終了し、高さが設定された後)...

于 2011-10-19T10:17:57.557 に答える
0

アセットをpngとして作成した場合は、9パッチを適用して、RelativeLayoutの背景として追加できます。

于 2011-10-19T12:55:31.500 に答える
0

また、RelativeLayout を使用してそれを行うのは難しいと感じています。行xmlのこのレイアウトを試してください。LinearLayout を使用します。

<?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="wrap_content" 
    android:orientation="vertical">
    <TextView android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="TextView" 
        android:id="@+id/textView2" 
        android:layout_alignParentTop="true" />
    <LinearLayout android:layout_width="fill_parent"
        android:layout_height="wrap_content">
        <LinearLayout android:layout_width="10dip" 
            android:layout_height="fill_parent"
            android:background="@drawable/errorindicator"/>       
        <TextView android:layout_width="0dip" 
            android:layout_height="wrap_content" 
            android:text="TextView" android:layout_weight="1.0" 
            android:id="@+id/textView1"
            android:textAppearance="?android:attr/textAppearanceMedium" 
            android:gravity="center"/>
   </LinearLayout>
</LinearLayout>
于 2011-10-18T17:39:55.443 に答える