在linearlayout上画个边框线

<?xml version="1.0" encoding="UTF-8"?>

<shape xmlns:android="http://schemas.android.com/apk/res/android"> 

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

<

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 6
    评论
Android 中,要在 LinearLayout 上添加上边框,可以通过两种方式来实现。 第一种方式是在布局的 XML 文件中使用属性来设置上边框。可以通过设置 LinearLayout 的 background 属性为一个具有上边框的 shape,来添加上边框样式。比如可以创建一个 drawable 文件,定义一个带有上边框的 shape,然后将该 drawable 文件设置为 LinearLayout 的 background。 示例代码如下: ```xml <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@drawable/border_with_top_line" ...> <!-- 子视图 --> </LinearLayout> ``` 其中 `border_with_top_line.xml` 是一个定义带有上边框的 shape 的 drawable 文件,示例代码如下: ```xml <shape xmlns:android="http://schemas.android.com/apk/res/android"> <stroke android:width="1dp" android:color="#000000" /> <padding android:top="1dp" /> </shape> ``` 第二种方式是在代码中动态设置上边框。可以通过 LinearLayout 的 `setPadding()` 方法设置上边框的高度,以及通过 `setBackgroundColor()` 方法设置上边框的颜色。 示例代码如下: ```java LinearLayout linearLayout = findViewById(R.id.linear_layout); // 设置上边框的颜色 linearLayout.setBackgroundColor(Color.BLACK); // 设置上边框的高度 int borderWidth = 1; // 单位为像素 linearLayout.setPadding(0, borderWidth, 0, 0); ``` 以上就是在 AndroidLinearLayout 上添加上边框的两种方式。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值