首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何将子布局的高度和配合设置为适合父布局?

问如何将子布局的高度和配合设置为适合父布局?
EN

Stack Overflow用户
提问于 2016-12-17 09:08:21
回答 3查看 1.4K关注 0票数 0

我是android的新手,我试图使用xml作为背景来制作circular layouts。现在我有一个父相对布局,它有一个子相对布局。父相对布局具有具有角半径的背景xml,并显示为圆圈。现在,内部相对布局/子布局也必须继承它并成为一个圆,对吗?但是它不是!子布局的高度和宽度为match_parent & match_parent。那么,如何使子布局的高度和宽度与父级的圆相匹配呢?

代码语言:javascript
复制
  <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

代码语言:javascript
复制
<?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。

提前感谢!

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2016-12-17 09:28:19

你可以试着这样做,希望这能帮到你。

代码语言:javascript
复制
<?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>
票数 -1
EN

Stack Overflow用户

发布于 2016-12-17 09:35:23

照做

代码语言:javascript
复制
  android:radius="250dp"

相反,所有拐角半径:

代码语言:javascript
复制
<?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
EN

Stack Overflow用户

发布于 2016-12-17 09:36:34

首先,如果你的父母布局是圆圈,这并不意味着,你的孩子也是圆形的。

第二,在你的父母也不是圆形的情况下--它是矩形的,你只能隐藏它的角并向你展示另一个部分。这就是为什么,当你使用匹配父母或其他东西时,它会给你正方形而不是圆圈。

在孩子而不是父母身上使用你的拖鞋。

或者您也可以使用Dileep Patel's answer来实现正方形内圆的目的。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41197032

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档