如何更改图层列表中的可绘制项目 Android Studio

How to Change Drawable item in Layer List Android Studio

这是我的问题:

如果我直接调用layer-list,我是没有问题的。但是我想更改图层列表中的可绘制对象,当我在 java 侧执行此操作时,我添加的可绘制图像占据了屏幕。

这是我的旗帜xml

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!-- First assign id to the list item-->
<item android:id="@+id/color">
    <shape android:shape="rectangle">
        <corners android:radius="10dp"/>
        <stroke android:width="2dp"
            android:color="#000000" />
        <solid android:color="@color/colorAccent" />
    </shape>
</item>
<item android:id="@+id/change_flag" android:bottom="2dp">
    <bitmap android:src="@drawable/tr1" android:gravity="center"/>
</item>

这里是java代码

LayerDrawable layerDrawable = (LayerDrawable) ContextCompat.getDrawable(this, R.drawable.flag);
        assert layerDrawable != null;
        Drawable drawable = ContextCompat.getDrawable(
                this, R.drawable.tr1);
        layerDrawable.setDrawableByLayerId(R.id.change_flag, drawable);

        buttons[i] = inflatedView.findViewById(getResources().getIdentifier("button" + i, "id", getPackageName()));
        
        buttons[i].setBackground(layerDrawable);

我想要这个

但这发生了

我卡住了,我需要一些帮助。

这只是一个简单的错误,只是删除位图并为项目提供可绘制对象...

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!-- First assign id to the list item-->
<item android:id="@+id/color">
    <shape android:shape="rectangle">
        <corners android:radius="10dp"/>
        <stroke android:width="2dp"
            android:color="#000000" />
        <solid android:color="@color/colorAccent" />
    </shape>
</item>
<item android:id="@+id/change_flag" android:bottom="2dp" android:drawable="@drawable/tr1" android:gravity="center">
</item>