1

だから、私はFrameLayoutを持っています:

<FrameLayout
        android:id="@+id/btn"
        android:layout_width="50dp"
        android:layout_height="50dp" >

        <ImageButton
            android:id="@+id/b"
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:background="@drawable/background" />
        <ImageButton
            android:id="@+id/bbtn"
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:background="@drawable/testcontur1" />           
    </FrameLayout>

私が知らないのは、レイヤーリストと同様に「機能」するように、このフレームレイアウトを間に何を置くかです。レイヤーリストの例は次のようになります。

<?xml version="1.0" encoding="utf-8"?>
      <layer-list xmlns:android="http://schemas.android.com/apk/res/android" >

        <item android:id="@+id/backgr">
            <bitmap android:gravity="center" android:src="@drawable/background" />
        </item>

        <item android:id="@+id/contur">
            <bitmap android:gravity="center" android:src="@drawable/testcontur1" />
        </item>

</layer-list>

したがって、基本的に、Java で最初のビットマップへの参照を何らかの方法で取得する必要があります。

 <bitmap android:gravity="center" android:src="@drawable/background" />

しかし、とにかくこれを管理することはできないので、これを達成する唯一の方法は、frameLayout を使用し、その中に imagebutton (または imageview など) を使用し、その ID で参照を取得することだと思います。

誰にも役立つとは思えませんが、I need this.I need the reference to the bitmap / ImageButton to be able to allow this like:

reference.getBackground().mutate().setColorFilter(Color.RED ,PorterDuff.Mode.Multiply);

私は早朝からそれを達成しようとしていて、どこにも行けないので、これに関する助けや考えは素晴らしいでしょう.

4

1 に答える 1

0

レイヤー ドローアブルへの参照を取得できます。次に、

public Drawable getDrawable (int index)

必要な特定のレイヤーへの参照を取得するメソッド。その後は、お好きなように進めてください。

http://developer.android.com/reference/android/graphics/drawable/LayerDrawable.html#getDrawable(int)

私はこれを試していませんが、うまくいくはずです。

于 2015-05-10T17:00:06.770 に答える