首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何将拐角半径应用于LinearLayout

如何将拐角半径应用于LinearLayout
EN

Stack Overflow用户
提问于 2012-04-09 21:53:36
回答 5查看 155.1K关注 0票数 133

我想做一个圆角边框的布局。如何在LinearLayout中应用特定大小的半径

EN

回答 5

Stack Overflow用户

回答已采纳

发布于 2012-04-09 22:20:18

可以在可绘制文件夹中创建XML文件。例如,将其命名为shape.xml

shape.xml

代码语言:javascript
复制
<shape
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle"   >

    <solid
        android:color="#888888" >
    </solid>

    <stroke
        android:width="2dp"
        android:color="#C4CDE0" >
    </stroke>

    <padding
        android:left="5dp"
        android:top="5dp"
        android:right="5dp"
        android:bottom="5dp"    >
    </padding>

    <corners
        android:radius="11dp"   >
    </corners>

</shape>

<corner>标签用于您的特定问题。

根据需要进行更改。

在你的whatever_layout_name.xml

代码语言:javascript
复制
<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:layout_margin="5dp"
    android:background="@drawable/shape"    >
</LinearLayout>

这是我在应用程序中通常做的事情。希望这能帮上忙。

票数 301
EN

Stack Overflow用户

发布于 2012-04-09 21:57:51

您将使用Shape Drawable作为布局的背景并设置其cornerRadius。Check this blog获取详细的教程。

票数 11
EN

Stack Overflow用户

发布于 2018-03-17 15:40:47

布局

代码语言:javascript
复制
<LinearLayout 
    android:id="@+id/linearLayout"
    android:layout_width="300dp"
    android:gravity="center"
    android:layout_height="300dp"
    android:layout_centerInParent="true"
    android:background="@drawable/rounded_edge">
 </LinearLayout>

可绘制文件夹rounded_edge.xml

代码语言:javascript
复制
<shape 
xmlns:android="http://schemas.android.com/apk/res/android">
    <solid 
        android:color="@android:color/darker_gray">
    </solid>
    <stroke 
         android:width="0dp" 
         android:color="#424242">
    </stroke>
    <corners 
         android:topLeftRadius="100dip"
         android:topRightRadius="100dip"
         android:bottomLeftRadius="100dip"
         android:bottomRightRadius="100dip">
    </corners>
</shape>
票数 11
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10074249

复制
相关文章

相似问题

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