Android中给LinearLayout设置边框

找到好多人的,都是文章随便copy,自己都不验证下,特别说LinearLayout中可以设置他的divider属性的,我在Android Studio中试了,根本显示不出来,这边是csdn上一个朋友回答的,我收藏了,放到这里,后面备用。

1.定一个underline的xml文件,把它放到drawable下

underline.xml

<?xml version="1.0" encoding="UTF-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
    <!-- 连框颜色值 -->
    <item>
        <shape>
            <solid android:color="#dddddd" />
        </shape>
    </item>
    <!-- 主体背景颜色值 -->
    <item android:bottom="1dp"> <!--设置只有底部有边框-->
        <shape>
            <solid android:color="#ffffff" />
        </shape>
    </item>
</layer-list>

2.然后在LinearLayout中引用该布局。就会出现下边框

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_marginRight="5dp"
        android:layout_marginLeft="5dp"
        android:paddingBottom="5dp"
        android:paddingTop="5dp"
        android:paddingRight="5dp"
        android:background="@drawable/linearlayout_underline"
        android:layout_height="wrap_content">

        <TextView
            android:text="余额:5611.19元"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="@color/red_font"
            android:textSize="18dp"
            android:id="@+id/member_balance"
            android:layout_weight="1"
            android:textAlignment="textEnd"/>
    </LinearLayout>

3.实现的效果图如下:

转载于:https://my.oschina.net/u/1399599/blog/829749

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值