标签: android-shape

android sdk中的嵌套形状

嗨,我想绘制一个有三个矩形形状的形状:1.纯色2.渐变3.白线我该怎么做?当我尝试这个时,它不起作用.布局具有父颜色.

<shape 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle"
    android:height="60px"
    >
    <shape 
        android:shape="rectangle" 
        android:height="30px"
        >
        <solid 
            android:color="#ff297baf" 
            />
    </shape>
    <shape 
        android:shape="rectangle"
        android:height="30px"
        >
         <gradient
  android:type="linear"
  android:startColor="#ff297baf"
  android:endColor="#ff16c0e3"
  android:angle="270"/> 
    </shape>
    <shape
        android:shape="rectangle"
        android:height="3px"
        >
        <solid 
            android:color="#FFFFFFFF"
            />
    </shape>
</shape>
Run Code Online (Sandbox Code Playgroud)

我试图用3种颜色制作渐变.从纯色开始#ff297baf,以60%开始渐变#ff297baf,#ff16c0e3然后在末尾添加一条渐变线.

android shapes xamarin.android android-shape

2
推荐指数
1
解决办法
7327
查看次数

Android:如何使用多色渐变绘制图形?

我做的:

  ShapeDrawable.ShaderFactory shaderFactory = new ShapeDrawable.ShaderFactory() {
        @Override
        public Shader resize(int width, int height) {
            LinearGradient linearGradient = new LinearGradient(0, 0, width, height,
                    new int[]{
                            0xF44336,
                            0xFFB74D,
                            0xFFE082,
                            0xAED581,
                            0x4CAF50,
                            0xAED581,
                            0xFFE082,
                            0xFFB74D,
                            0xF44336},
                    new float[]{
                            0, 0.125f, 0.25f, 0.375f, 0.5f, 0.625f, 0.75f, 0.875f, 1.0f},
                    Shader.TileMode.REPEAT);
            return linearGradient;
        }
    };
    PaintDrawable paint = new PaintDrawable();
    paint.setShape(new RectShape());
    paint.setShaderFactory(shaderFactory);
Run Code Online (Sandbox Code Playgroud)

但是,当我在视图中将其设置为背景时,我什么都看不到。

android linear-gradients android-drawable android-shape

2
推荐指数
1
解决办法
1904
查看次数

有什么方法可以创建半圆作为形状吗?

我想为我的应用程序创建特殊视图。它是垂直的虚线和上下两个半圆。有什么方法可以将其创建为可绘制的单个形状吗?我做了虚线,但我不能做半圆。

它应该是这样的。

在此处输入图片说明

垂直虚线:

<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android" android:fromDegrees="90" android:toDegrees="90">
    <shape
            android:shape="line">
        <stroke
                android:color="#777777"
                android:dashWidth="7dp"
                android:dashGap="5dp"
                android:width="2dp"/>
    </shape>
</rotate>
Run Code Online (Sandbox Code Playgroud)

我发现有人试图做半圈,但它很大。我只需要小圆圈。它甚至不是圆圈。

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <corners
            android:bottomLeftRadius="100000dp"
            android:topLeftRadius="0dp"
            android:bottomRightRadius="100000dp"
            android:topRightRadius="0dp" />

    <solid android:color="#777777" />
</shape>
Run Code Online (Sandbox Code Playgroud)

android android-drawable android-shape

1
推荐指数
1
解决办法
2866
查看次数

Android - SpotShadowAlpha 仅适用于线性布局

我正在使用线性布局的高程属性,但阴影太亮。我只需要一个较暗的阴影用于线性布局。

我添加android:spotShadowAlpha到我的styles.xml. 它有效,但不仅仅适用于线性布局。每个视图都有一个较暗的阴影。

样式.xml

<resources>
    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="android:ambientShadowAlpha">0</item>
        <item name="android:spotShadowAlpha">0.55   </item>
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>
</resources>
Run Code Online (Sandbox Code Playgroud)

线性布局在activity_main.xml

<LinearLayout
        android:id="@+id/linl"
        android:layout_width="250dp"
        android:layout_height="250dp"
        android:layout_marginStart="55dp"
        android:layout_marginTop="208dp"
        android:layout_marginEnd="56dp"
        android:layout_marginBottom="209dp"
        android:background="@drawable/custom_buttom"
        android:elevation="70dp"
        android:orientation="horizontal"

        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

背景@drawable/custom_buttom

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
    <solid android:color="#FFFFFF"/>
    <corners android:radius="999dp"/>
</shape>
Run Code Online (Sandbox Code Playgroud)

android android-layout android-styles android-shape

1
推荐指数
1
解决办法
2780
查看次数

如何在心形drawable xml中添加边框(描边)线

  • 如下我绘制可绘制的 xml 像心形
  • 但我想添加边框线,如(描边)
  • 我遇到一些困难如何添加该行

    <path
        android:fillColor="#a39f9f"
        android:pathData="M12,21.35l-1.45,-1.32C5.4,15.36 2,12.28 2,8.5 2,5.42 4.42,3 7.5,3c1.74,0 3.41,0.81 4.5,2.09C13.09,3.81 14.76,3 16.5,3 19.58,3 22,5.42 22,8.5c0,3.78 -3.4,6.86 -8.55,11.54L12,21.35z"/>
    
    Run Code Online (Sandbox Code Playgroud)

xml android android-shape android-vectordrawable

0
推荐指数
1
解决办法
1847
查看次数

Android - What is the difference between these three xml files?

What is the difference between these three xml files in android?

xml file with selector as root element

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape android:shape="rectangle">
            <Further Designing ... />
            ...
        </shape>
    </item>
</selector>
Run Code Online (Sandbox Code Playgroud)

xml file with shape as root element

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
       android:shape="rectangle">
    <Further Designing ... />
    ...
</shape>
Run Code Online (Sandbox Code Playgroud)

xml file with layer-list as root element

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape android:shape="rectangle">
            <Further Designing ... />
            ...
        </shape>
    </item>
    <item android:bottom="1dp">
        <shape android:shape="rectangle">
            <Further …
Run Code Online (Sandbox Code Playgroud)

android android-layout android-xml android-shape

0
推荐指数
1
解决办法
67
查看次数