我是android的新手,并尝试使用xml作为背景制作circular layouts
。现在我有一个父相对布局,它有一个子相对布局。父相对布局具有带角半径的背景xml,并显示为圆形。现在内部相对布局/子布局也必须继承这个并且是一个圆圈吗?但它没有!子布局的高度和宽度为match_parent
& match_parent
。那么如何让子布局的高度和宽度适合父级的圆圈?
<RelativeLayout
android:layout_marginTop="12dp"
android:layout_below="@+id/view10"
android:layout_centerHorizontal="true"
android:layout_width="52dp"
android:gravity="center"
android:background="@drawable/dutycirclebackground"
android:layout_height="52dp">
<RelativeLayout
android:visibility="visible"
android:layout_width="match_parent"
android:gravity="center"
android:layout_height="match_parent">
</RelativeLayout>
</RelativeLayout>
这是后台xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" android:padding="10dp">
<solid android:color="#cc5228"/>
<corners
android:bottomRightRadius="25dp"
android:bottomLeftRadius="25dp"
android:topLeftRadius="25dp"
android:topRightRadius="25dp"/>
</shape>
这里,如果我为内部布局设置背景颜色并检查输出,我会得到square layout
但parent is a circle
。
提前致谢!
答案 0 :(得分:0)
做为
android:radius="250dp"
而是所有角半径:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval" android:padding="10dp">
<solid android:color="#cc5228"/>
<corners
android:radius="250dp" />
</shape>
答案 1 :(得分:0)
首先,如果你的父母布局是圆圈,那并不意味着,你的孩子也是圆形的。
其次,在你的情况下,你的父母也不是圆形的,它是矩形的形状,你可绘制的只隐藏它的角落并显示另一部分。这就是为什么,当你使用匹配父或其他东西时,它会给你方形而不是圆形。
在孩子而非父母中使用你的drawable。
或者你可以使用Dileep Patel's answer来达到圈内广场的目的
答案 2 :(得分:-1)
你可以尝试这个希望这可以帮助你..
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:auto="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="52dp"
android:layout_height="52dp"
android:layout_below="@+id/view10"
android:layout_centerHorizontal="true"
android:layout_margin="10dp"
android:layout_marginTop="12dp"
android:background="@drawable/dutycirclebackground"
android:gravity="center"
android:orientation="vertical"
tools:context=".MainActivity">
<RelativeLayout
android:layout_width="52dp"
android:layout_height="52dp"
android:layout_centerHorizontal="true"
android:layout_margin="10dp"
android:layout_marginTop="12dp"
android:background="@drawable/dutycirclebackground"
android:gravity="center"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/darker_gray"
android:gravity="center" />
</RelativeLayout>
</RelativeLayout>