所以,我有一个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,在它里面有一个image按钮(或imageview,不管怎样),并通过它的ID获得对它的引用。
我怀疑它对任何人都有帮助,但我也会写下我需要这个。我需要位图/ImageButton的引用,以便能够实现以下内容:
reference.getBackground().mutate().setColorFilter(Color.RED ,PorterDuff.Mode.Multiply);
任何帮助或想法都会很好,因为我从一大早就一直在努力实现这一点,但我哪儿也去不了。
您可以获得对您的图层drawinable的引用。然后使用
public Drawable getDrawable (int index)
方法获取对所需特定层的引用。之后,你可以按照自己的意愿进行。
http://developer.android.com/reference/android/graphics/drawable/LayerDrawable.html#getDrawable(int)
我还没有试过这个,但我确信它会起作用。