Half circle shape not work

前端 未结 5 2048
面向向阳花
面向向阳花 2020-11-30 23:42

I try to create half circle background, in development IDE preview it works, but when I launch in emulator it doesn\'t work.

Here is my shape c

相关标签:
5条回答
  • 2020-12-01 00:04

    Try this. Remove the gradient part then it will look like same as you want.

    <item>
        <shape xmlns:android="http://schemas.android.com/apk/res/android"
            android:shape="rectangle">
            <solid android:color="#00B0EA" />
    
        </shape>
    </item>
    <item
        android:bottom="400dp"
        android:left="-100dp"
        android:right="-100dp"
        android:top="-200dp">
        <shape xmlns:android="http://schemas.android.com/apk/res/android"
            android:shape="oval">
            <gradient
                android:angle="90"
                android:endColor="#65FFFFFF"
                android:startColor="#65FFFFFF" />
        </shape>
    </item>
    <item
        android:bottom="402dp"
        android:left="-100dp"
    
        android:right="-100dp"
        android:top="-280dp">
        <shape xmlns:android="http://schemas.android.com/apk/res/android"
            android:shape="oval">
            <solid android:color="#FFFFFF" />
        </shape>
    </item>
    

    0 讨论(0)
  • 2020-12-01 00:05

    you can try this :

    <?xml version="1.0" encoding="utf-8"?>
    <shape
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:shape="rectangle">
        <solid android:color="#900021df"/>
        <size
            android:width="10dp"
            android:height="5dp"/>
        <corners
            android:bottomLeftRadius="20dp"
            android:bottomRightRadius="20dp"/>
    </shape>
    

    it gives this shape:

    0 讨论(0)
  • 2020-12-01 00:08

    You cannot create a semicircle from xml. but you could achieve what you are looking for using a circle with appropriate margin & padding.

    You can use a circle shape .xml file. Create a fixed sized circle like this:

    Example:

    <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android"
           android:shape="oval"
           android:useLevel="false" >
       <solid android:color="#006AC5" />
       <size
        android:height="50dp"
        android:width="50dp" />
    </shape>
    

    0 讨论(0)
  • 2020-12-01 00:10

    Background.xml


    <?xml version="1.0" encoding="utf-8"?>
    <layer-list  xmlns:android="http://schemas.android.com/apk/res/android">
        <item>
            <shape xmlns:android="http://schemas.android.com/apk/res/android"
                android:shape="rectangle">
                <solid android:color="#FFFFFF" />
            </shape>
        </item>
        <item
            android:bottom="410dp"
            android:left="-100dp"
            android:right="-100dp"
            android:top="-300dp">
            <shape xmlns:android="http://schemas.android.com/apk/res/android"
                android:shape="oval">
    
                <solid android:color="#7181A1" />
            </shape>
        </item>
    </layer-list>
    

    Output like

    0 讨论(0)
  • 2020-12-01 00:26

    curve_toolbar_bg.xml

    <?xml version="1.0" encoding="utf-8"?>
    <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
        <item>
            <shape android:shape="rectangle"/>
        </item>
        <item
            android:bottom="0dp"
            android:left="-100dp"
            android:right="-100dp"
            android:top="-80dp">
            <shape android:shape="oval">
                <solid android:color="@color/colorPrimary" />
            </shape>
        </item>
    </layer-list>
    

    activity_main.xml

    <?xml version="1.0" encoding="utf-8"?>
    <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/container"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    
        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="0dp"
            android:layout_height="?android:attr/actionBarSize"
            android:background="@drawable/rounded_corner"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintVertical_bias="0.0">
    
        </android.support.v7.widget.Toolbar>
    </android.support.constraint.ConstraintLayout>
    

    0 讨论(0)
提交回复
热议问题