android - 带有图层列表的自定义绘图

标签 android layer-list

我将创建一个如下图所示的可绘制对象,其中包含箭头图像。

当我使用图层列表时,箭头图像出现在我的可绘制对象的中间!!!

请告诉我如何实现它......

更新: 这是我的图层列表:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item >
    <shape android:shape="rectangle">
        <corners android:radius="5dp"/>
        <solid android:color="#d5d5d5"/>
        <stroke android:width="1dp" android:color="#242425"/>
    </shape>
</item>

<item android:drawable="@drawable/ic_arrow"></item>

最佳答案

创建一个可绘制资源文件,将位图设置为根元素,然后设置 android:gravity="left" 并使用此位图文件作为图层列表项中的可绘制文件。

<?xml version="1.0" encoding="utf-8"?>
<bitmap
       android:gravity="left"
       xmlns:android="http://schemas.android.com/apk/res/android"
       android:src="@drawable/ic_launcher"/>

图层列表:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

        <item>
           <shape android:shape="rectangle">

                 <stroke  android:width="1dp" android:color="@color/blue" />
                <solid android:color="@color/silver" />

            </shape>
       </item>

       <item android:drawable="@drawable/stack" />

</layer-list>

关于android - 带有图层列表的自定义绘图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28663333/

相关文章:

java - 使用蓝牙键盘和语音助手的TextView按钮

android - 从数据库/网站调用和使用音频、视频和图像文件

java - 多次使用 drawable 但颜色不同

android - 无法使用模拟器,使用 react-native 和 expo

android - Kotlin如何在队列中发出多个请求

android - 包含带外描边的圆的图层列表

android - 将图层列表转换为位图可能不起作用

安卓 4.2 : IllegalstateException: One or more children of this LayerDrawable does not have constant state

android - 在 Layer-List 中使用 XML 更改布局的边距

Android如何知道在任何情况下打开了哪个应用程序