Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/231.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android将Drawable和Shape组合成一个单一的Drawable(可编程)_Android_Android Drawable - Fatal编程技术网

Android将Drawable和Shape组合成一个单一的Drawable(可编程)

Android将Drawable和Shape组合成一个单一的Drawable(可编程),android,android-drawable,Android,Android Drawable,我正在通过编程方式设置一个单选按钮的android:drawable,如下所示: Drawable unchecked = getResources().getDrawable(R.drawable.ic_room_car); Drawable d= getResources().getDrawable(R.drawable.ic_room_car); Shape circle = ?????; ??? checked = combine circle and d SateListDra

我正在通过编程方式设置一个单选按钮的
android:drawable
,如下所示:

Drawable unchecked = getResources().getDrawable(R.drawable.ic_room_car);

Drawable d= getResources().getDrawable(R.drawable.ic_room_car);

Shape circle = ?????;
??? checked = combine circle and d


SateListDrawable states= new StateListDrawable();
states.addState(new int[] {android.R.attr.state_checked}, checked);
states.addState(new int[] {}, unchecked);

((RadioButton)findViewById(R.id.icon_1)).setButtonDrawable(states);
基本上,它有一个自定义图标,当它未选中时,我从参考资料中读取该图标,当选中时,我想在图标后面画一个圆圈

未选中的行为在第二个addState行中设置,并且它正在工作。我的问题是如何以编程方式绘制一个圆,然后以某种方式将它与我从参考资料中阅读的可绘制图形结合起来。

这是一个图层列表

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@mipmap/ic_launcher" android:left="10dp" android:right="10dp" android:top="10dp" android:bottom="10dp">
    </item>
    <item>
       <shape android:shape="oval">
            <solid android:color="@android:color/transparent"></solid>
            <stroke android:color="#4b14b1" android:width="1dp"></stroke>
            <size android:height="50dp" android:width="50dp"></size>
        </shape>
    </item>
</layer-list>


我知道如何在xml中这样做,但我不知道如何在代码中这样做。我试着在代码中创建一个层列表,但它没有绘制。只需找出代码中正确的等价于层列表的是LayerDrawable。现在我终于成功了!