Android shape drawable xml 未在设备或模拟器上绘制

标签 android xml android-layout android-widget

我就是想不通。我在 res/drawable/start_light.xml 中有这个形状

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="ring"
    android:innerRadius="20dp"
    android:thickness="0dp"
    android:useLevel="false">
    <solid android:color="#FF0000" />
</shape>

在 res/values/styles.xml 中我有:

<?xml version="1.0" encoding="UTF-8"?>
<resources>
    <style name="StartLight">
        <item name="android:layout_height">50dp</item>
        <item name="android:layout_width">50dp</item>
        <item name="android:background">@drawable/start_light</item>
    </style>
</resources>

在主布局中我有:

<LinearLayout 
    android:id="@+id/linearLayout1" 
    android:layout_gravity="center_horizontal" 
    android:layout_width="wrap_content" 
    android:gravity="center_vertical" android:layout_height="150dp">
    <ImageView android:src="@drawable/start_light" android:id="@+id/light5" android:layout_width="50dp" android:layout_height="50dp"></ImageView>
    <View style="@style/StartLight" android:id="@+id/light4"></View>
    <View style="@style/StartLight" android:id="@+id/light3"></View>
    <View style="@style/StartLight" android:id="@+id/light2"></View>
    <View style="@style/StartLight" android:id="@+id/light1"></View>
</LinearLayout>

以以太方式,使用 View 或 ImageView 我在模拟器或设备上的布局中看不到任何红色圆圈。在 xml 图形设计器上,它们在那里。我在这里缺少什么?

最佳答案

替换你的可绘制形状
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="ring"
    android:innerRadius="0dp"
    android:thickness="20dp"
    android:useLevel="false">
    <solid android:color="#FF0000"/>
 </shape>

将厚度设置为 0 使其在模拟器上不可见。 这里我将 innerRadius 设置为 0。

关于Android shape drawable xml 未在设备或模拟器上绘制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7649446/

相关文章:

android - Android 设备上的 ADB 输出

android - setImageResource 内存不足错误

菜单选项中的android显示对话框不起作用

html - 如何正确使用 XPath preceding-sibling?

android - 为什么键盘将 tabhost 提升到顶部?

android - 带有设置 fragment 的 Activity 在横向上崩溃

c# - 如何解析 KML 文件以从 Placemark 元素检索坐标点?

xml - 只能具有两个文本值之一的元素?

android:如何将填充添加到 FrameLayout 内的 LinearLayout

java - 带有选项卡的 Activity 中的布局刷新问题