convert my layout into a circular ring shape

2019-02-26 06:08发布

I want to make my linear-layout in ring shape.

I followed this Links but i doesn't got ring layout instead I am getting a circular layout.

https://developer.android.com/guide/topics/resources/drawable-resource.html#Shape

How can I create the following layout in xml to use as a background for my android activities?

My xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.ring.MainActivity" >

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentTop="true"
    android:background="@drawable/ring"
    >

</LinearLayout>

and ring.xml in drawable

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
 android:shape="ring"
 android:innerRadius="90dp"
 android:thickness="10dp"
 android:useLevel="false" >

<solid android:color="#ababf2" />

and I am just getting a circle in my layout not ring.Sorry i cannot upload an image of my output because of my short reputation.

2条回答
ゆ 、 Hurt°
2楼-- · 2019-02-26 07:04

Try this:

ring.xml

<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="ring"
android:innerRadius="50dp"
android:thickness="2dp"
android:useLevel="false">
<stroke android:width="2dp"
    android:color="#ababf2"/>
<solid android:color="@android:color/transparent" />

</shape>

your xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

<RelativeLayout
        android:id="@+id/rel"
        android:layout_width="120dp"
        android:layout_height="120dp"
        android:layout_centerInParent="true"
        android:background="@drawable/ring" >
    </RelativeLayout>
</RelativeLayout>
查看更多
我想做一个坏孩纸
3楼-- · 2019-02-26 07:05

Try this!

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:innerRadius="0dp"
    android:shape="ring"
    android:thicknessRatio="3"
    android:useLevel="false" >
    <solid android:color="@android:color/transparent" />

    <stroke
        android:width="20dp"
        android:color="@android:color/black" />
</shape>
查看更多
登录 后发表回答