android holder加入圆框

时间:2020-11-07 17:42:08   收藏:0   阅读:29

android text加入圆角边框的方法是

声明一个自定义的一个xml样式,类似

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
 android:shape="oval"
 <solid android:color="#00FF00" />
 <size
  android:width="15dp"
  android:height="15dp" />
</shape>

然后在原布局TextView标签中声明使用

 android:background="@drawable/style"

今天在viewholder  的adaper中会发现问题

使用这个方法并不能正常显示圆角边框

holder.setBackgroundColor()

展示出来的还是矩形,并且颜色也有问题

解决方法:

声明的自定义xml文件中要填充上颜色并声明是矩形

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle"
    >
    <solid android:color="@color/audit1"></solid>
    <corners android:radius="4dp" />
</shape>

然后在TextView标签中同样声明

android:background="@drawable/style"

只是在adapter中holder的调用方法不同

 holder.setBackgroundRes(R.id.list_info,R.drawable.style);

使用.setBackgroundRes的方法,第一参数写明要规定圆角边框的区域,第二个参数写明要套用的模板

 

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!