【发布时间】:2016-12-17 20:18:00
【问题描述】:
我是 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。
提前致谢!
【问题讨论】:
-
移除子布局中的 android:gravity="center"
-
@sasikumar,删除并检查,但仍然是一个正方形
-
@Sidharth MA 你在实际设备上运行过它吗?
标签: android android-layout geometry android-relativelayout