Java Android:setBackground方法更改视图';s高度
当我以编程方式更改背景色时,它会拉伸Java Android:setBackground方法更改视图';s高度,java,android,mobile,Java,Android,Mobile,当我以编程方式更改背景色时,它会拉伸TextView的宽度 @Override public void onBindViewHolder(@NonNull ViewHolder holder, int position) { holder.textCategory.setText(categoryList.get(position).getName()); if (Build.VERSION.SDK_INT >= Build.VERSION_CODE
TextView
的宽度
@Override
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
holder.textCategory.setText(categoryList.get(position).getName());
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
if (categoryIndex == position) {
holder.textCategory.setBackground(context.getDrawable(R.drawable.categories_background));
} else {
holder.textCategory.setBackground(context.getDrawable(R.drawable.temp_background));
}
}
}
这是所选的语句
里面有空格或不同的字符吗?你能调试一下吗?谢谢里面有空格或不同的字符吗?你能调试一下吗?谢谢你能给我看看这张照片吗?我不明白你说的“变宽”是什么意思。@PayaKamyar屏幕截图已经添加。你能展示图片吗?我不明白你说的“变宽”是什么意思。@PayaKamyar屏幕截图已经添加。
<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView
android:layout_margin="3dp"
android:background="@drawable/categories_background"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:textStyle="bold"
android:fontFamily="sans-serif-light"
android:textAllCaps="true"
android:id="@+id/categoryName"
android:paddingBottom="10dp"
android:paddingTop="10dp"
android:paddingRight="10dp"
android:paddingLeft="10dp"
android:textColor="#262626"
android:textSize="16sp"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</androidx.cardview.widget.CardView>