2016-12-17 121 views
0

我是新来的机器人,并试图使用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 layoutparent is a circle

在此先感谢!

+0

删除安卓重力=“中心”子布局 – sasikumar

+0

@sasikumar,删除和检查,但仍然是一个方形 –

+0

@Sidharth MA没有ü运行在一个实际的设计? –

回答

-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> 
+0

非常感谢你的帮助,它帮助了我! –

+0

欢迎兄弟..请也upvote这.. –

+0

为什么downvote这个请详细说明.. –

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> 
0

的第一件事情,如果你的父母布局是圆的并不意味着,你的孩子也是圆形的。第二,在你的情况下你的父母也不是圆形,它是矩形的形状,你可绘制的只隐藏它的角落并向你展示另一部分。这就是为什么,当你使用匹配父母或其他东西时,它会给你方形而不是圆形。

在儿童不是父母的情况下使用您的drawable。

,或者您可以使用Dileep Patel's answer你方的目的,内圆