您的位置:首页 > 其它

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

2017-07-14 17:01 351 查看

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);


如果用这段代码,会引起白屏,具体原因一定要查一查,暂时我不明白为什么,希望路过的高手可以解答下
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: