Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/366.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Android:setBackground方法更改视图';s高度_Java_Android_Mobile - Fatal编程技术网

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>