将我的布局转换为圆环形状

2023-12-01

我想将我的线性布局做成环形。

我遵循了此链接,但没有得到环形布局,而是得到了圆形布局。

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

如何在 xml 中创建以下布局以用作我的 android 活动的背景?

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>

和可绘制的ring.xml

<?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" />

我的布局中只是出现了一个圆圈而不是圆圈。抱歉,由于我的声誉不佳,我无法上传我的输出图像。


尝试这个:

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>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

将我的布局转换为圆环形状 的相关文章

随机推荐