You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

Android开发问题:如何用Shape Drawable制作目标样式图形?

Fixing Your Android Shape to Match supposed.bmp

Hey there! Let's get that shape looking exactly like your target supposed.bmp. Right now, your code creates a solid filled oval (which matches actual.bmp), so we just need to tweak the XML based on what your ideal style is. Here are the most common fixes based on typical target shapes:

Case 1: Your supposed.bmp is a hollow oval with a border

If the target is an empty oval with a colored outline, you'll want to remove the solid fill and properly configure the stroke attribute (your original code cut off here). Try this:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="oval">
    <!-- Make the inner area transparent -->
    <solid android:color="@android:color/transparent" />
    <!-- Set border width and color (adjust values to match your target) -->
    <stroke
        android:width="2dp"
        android:color="#199900" />
    <size
        android:height="20dp"
        android:width="20dp" />
</shape>

Case 2: Your supposed.bmp has a two-tone "ring" effect

If the target is an oval with a darker outer ring and a lighter inner fill (or vice versa), use a layer-list to stack two ovals:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <!-- Bottom layer: larger oval for the outer ring color -->
    <item>
        <shape android:shape="oval">
            <solid android:color="#your_outer_ring_color" />
            <size
                android:height="22dp"
                android:width="22dp" />
        </shape>
    </item>
    <!-- Top layer: smaller oval for the inner fill, using margin to show the ring -->
    <item android:margin="1dp">
        <shape android:shape="oval">
            <solid android:color="#199900" />
            <size
                android:height="20dp"
                android:width="20dp" />
        </shape>
    </item>
</layer-list>

If neither of these matches your supposed.bmp, just describe the exact details of the target (like gradient fills, shadows, rounded corners that aren't full oval, etc.) and we can refine the code further!

内容的提问来源于stack exchange,提问作者Yu Leung

火山引擎 最新活动