FrameLayouts使用类似于图层列表

问题描述 投票:0回答: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>

我不知道的是将这个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获取它。

我怀疑它对任何人有帮助,但我也会写我需要这个。我需要对bitmap / ImageButton的引用,以便能够像这样:

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

对此的任何帮助或想法都会很棒,因为我一直在努力实现从早上开始就无法到达任何地方。

android android-framelayout layer-list
1个回答
0
投票

您可以获得对图层drawable的引用。然后使用

public Drawable getDrawable (int index)

获取所需特定图层的引用的方法。之后,您可以按照自己的意愿行事。

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

我没有试过这个,但我确信它应该有效。

© www.soinside.com 2019 - 2024. All rights reserved.