LinearLayout通过shape设置圆角,但是最下面的textView却没有圆角

本文介绍了一个LinearLayout布局中实现底部TextView圆角效果的方法。通过自定义shape背景并仅设置底部圆角,解决了整体视图圆角不一致的问题。同时提供了一种动态改变TextView背景颜色的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1、效果图

这里写图片描述

2、问题描述

背景:上图是一个vertical的linearlayout,最底部是一个textView(我设置了linearlayout的高度正好包含这些视图,不能再高),我希望的效果是整个视图都有圆角,而上图却只有上方有圆角

3、解决办法

单独给底部的textView设置一个shape作为背景,只设置底部有圆角(不要设置多个corners节点,否则只有第一个有效果)

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" >

    <corners
        android:topLeftRadius="0dp"
        android:topRightRadius="0dp"
        android:bottomLeftRadius="3dp"
        android:bottomRightRadius="3dp"
        />

    <solid android:color="@android:color/darker_gray"></solid>

</shape>

然后,由于我这个textView的颜色是动态的,

GradientDrawable drawable = (GradientDrawable) textview.getBackground();
        drawable.setColor(Color.parseColor(bean.buttonColor));

这段代码就可以修改颜色了

//        GradientDrawable gd = new GradientDrawable();//创建drawable
//        gd.setColor(Color.parseColor(bean.buttonColor));
//        float[] radious={0,0,3,3};
//        gd.setCornerRadii(radious);

//        textview.setBackgroundDrawable(gd);

如果用这段代码,会引起白屏,具体原因一定要查一查,暂时我不明白为什么,希望路过的高手可以解答下

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值