所以,我有一个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>我不知道的是如何把这个framelayout放在中间,这样它就会像layer-list一样“行为”。layer-list的例子如下:
<?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.This的引用:
<bitmap android:gravity="center" android:src="@drawable/background" />但是我无论如何都不能做到这一点,所以我想实现这一点的唯一方法是使用一个frameLayout,里面有一个图像按钮(或图像视图,随便什么),并通过它的ID来引用它。
我怀疑它对任何人都有帮助,但我也会写I need this。我需要对位图/ ImageButton的引用,以便能够实现以下内容:
reference.getBackground().mutate().setColorFilter(Color.RED ,PorterDuff.Mode.Multiply);任何关于这方面的帮助或想法都将是很棒的,因为我从一大早就一直在努力实现这一点,但我什么也达不到。
发布于 2015-05-11 01:00:07
你可以得到你的图层的引用可绘制。然后使用
public Drawable getDrawable (int index)方法来获取对所需特定层的引用。在此之后,您可以按您的意愿进行操作。
http://developer.android.com/reference/android/graphics/drawable/LayerDrawable.html#getDrawable(int)
我还没有尝试过,但我很确定它应该可以工作。
https://stackoverflow.com/questions/26780274
复制相似问题