android linearlayout 下边框,如何围绕Android LinearLayout创建边框?

如何围绕Android LinearLayout创建边框?

我有一个大的布局,里面有一个较小的布局。

如何在小布局周围创建线条边框?

7个解决方案

193 votes

当然。 您可以为所需的任何布局添加边框。 基本上,您需要创建自定义drawable并将其添加为布局的背景。 例:

在drawable文件夹中创建一个名为customborder.xml的文件:

现在将其作为背景应用于较小的布局:

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:background="@drawable/customborder">

这应该够了吧。

另见:

[http://tekeye.biz/2012/add-a-border-to-an-android-layout]

如何在线性布局周围添加边框除了底部?

Anup Cowkur answered 2019-09-10T03:26:51Z

22 votes

在drawable文件夹中创建名为border.xml的XML,如下所示:

然后将此添加到线性布局作为背景,如下所示:

android:background="@drawable/border"

KDeogharkar answered 2019-09-10T03:27:21Z

10 votes

试试这个:

例如,让我们将res / drawable / my_custom_background.xml定义为:

(在drawable文件夹中创建此布局)layout_border.xml

android:color="#FF0000" />

android:bottom="1dp" />

android:bottomLeftRadius="0dp" android:topLeftRadius="5dp"

android:topRightRadius="0dp" />

main.xml中

android:layout_gravity="center"

android:layout_width="200dp"

android:layout_height="200dp"

android:background="@drawable/layout_border" />

Android_coder answered 2019-09-10T03:27:58Z

9 votes

在drawable文件夹中创建一个xml文件

android:width="2dp"

android:color="#B40404" />

android:bottom="5dp"

android:left="5dp"

android:right="5dp"

android:top="5dp" />

现在将此xml称为您的小布局背景

机器人:背景= “@绘制/ yourxml”

Vani answered 2019-09-10T03:28:35Z

3 votes

此解决方案只会添加边框,LinearLayout的主体将是透明的。

首先,在drawable文件夹border.xml中创建此边框drawable

android:shape="rectangle">

然后,在LinearLayout视图中,将border.xml添加为背景,如下所示

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical"

android:background="@drawable/border">

s-hunter answered 2019-09-10T03:29:12Z

3 votes

我会将Android文档链接添加到其他答案中。

[https://developer.android.com/guide/topics/resources/drawable-resource.html#Shape]

它描述了Shape Drawable和stroke的所有属性,用于设置边框。

例:

红色边界有透明背景。

mortalis answered 2019-09-10T03:29:57Z

2 votes

你也可以用实际的方式去做

GradientDrawable gradientDrawable=new GradientDrawable();

gradientDrawable.setStroke(4,getResources().getColor(R.color.line_Input));

然后将布局的背景设置为:

LinearLayout layout = (LinearLayout ) findViewById(R.id.ayout); layout .setBackground(gradientDrawable);

Vikram singh answered 2019-09-10T03:30:28Z

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值