8

私は2つの楕円形のドローアブルを重ね合わせようとしています.1つ目は透明です。ただし、私のやり方では、最初の楕円の色が2番目の楕円のサイズで表示されます。

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
    <shape android:shape="oval">
        <size android:width="15dp" android:height="15dp" />
        <solid android:color="#35000000"/>
    </shape>
</item>
<item>
    <shape android:shape="oval">
        <size android:width="5dp" android:height="5dp" />
        <solid android:color="#000000"/>
    </shape>
</item>
</layer-list>

これを意図したとおりに動作させるにはどうすればよいですか?

編集: ここに親があります:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ImageView
    android:id="@+id/imageView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/my_layerlist" />
</LinearLayout>
4

1 に答える 1

8

さまざまなタイプの XML ドローアブルについて多くの調査を行った結果、LayerDrawable(レイヤー リスト) がShapeDrawables個別にスケーリングされているようです。次にImageViewは をスケーリングしていLayerDrawableます。Google のこのガイドによると、 と の両方 ShapeDrawableのスケーリングLayerDrawableが懸念事項です。s は、持っている各アイテムLayerDrawableに必要なスケーリングをチェックします。彼らにはいくつかの解決策があります:

  • gravity「中心」など、スケーリングしないものに設定します。
  • ドローアブルをビットマップとして定義します。
  • ImageView をスケールしない scaleType に設定します。

ただし、これには 2 つの大きな問題がありgravityますbitmap。また、XML で ShapeDrawable を使用することはできませんbitmap。私はそれを正しくするために考えられるすべてを試しました。これが私のためにそれを修正した唯一のものです。

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
    android:id="@+id/imageView1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:src="@drawable/oval1"
    android:scaleType="center"  />
<ImageView
    android:id="@+id/imageView2"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:src="@drawable/oval2"
    android:scaleType="center"  />
</FrameLayout>

そのため、LayerDrawable を削除し、Shape を独自の XML に分離し、2 つの ImageView を作成しました。(簡単にするために、FrameLayoutに貼り付けました)。これがスケーリングを停止する唯一の方法でした。


試験手順

Android 2.1、3.0、4.0 でテスト済み

  • 変更された画像scaleType
  • 変更された画像widthheight
  • 分離された ShapeDrawable
  • LayerList を、分離された s を参照する属性を持つ s だけに変更しましitemdrawableshape
  • LayerList を、bitmap分離された を参照する に変更しましたshape
  • shapeの順序を変更

または、コードで実行することもできます。


于 2012-06-13T11:19:05.643 に答える