在Android中的Recyclerview上滚动时,项目视图的高度会降低

问题描述

我想显示名称列表。我正在使用recylerview进行显示。为此,我将Vertical TextView用作项目视图。它可以正常工作。但是问题是当我滚动recyclerview时,项目高度降低了

VerticalTextview类

public class VerticalTextView extends androidx.appcompat.widget.AppCompatTextView {
    boolean topDown;

    public boolean getTopDown(){
        return topDown;
    }
    public void setTopDown(boolean key){
        this.topDown=key;
    }

    public VerticalTextView(Context context,AttributeSet attrs){
        super(context,attrs);
        final int gravity = getGravity();

        if(Gravity.isVertical(gravity) && (gravity&Gravity.VERTICAL_GRAVITY_MASK) == Gravity.BOTTOM) {
            setGravity((gravity&Gravity.HORIZONTAL_GRAVITY_MASK) | Gravity.TOP);
            topDown = false;
        }else
            topDown = true;
    }


    @Override
    protected void onMeasure(int widthMeasureSpec,int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec,heightMeasureSpec);
        setMeasuredDimension(getMeasuredHeight(),getMeasuredWidth());

    }

    @Override
    protected void onDraw(Canvas canvas) {
        TextPaint tp =getPaint();
        tp.setColor(getCurrentTextColor());
        tp.drawableState=getDrawableState();
        canvas.save();

        if(topDown){
            canvas.translate(getWidth(),0);
            canvas.rotate(90);
        }else {
            canvas.translate(0,getHeight());
            canvas.rotate(-90);
        }

        canvas.translate(getCompoundPaddingLeft(),getExtendedPaddingTop());

        getLayout().draw(canvas);
        canvas.restore();



    }
}

这是我的物品布局

<layout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:sayaki="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto">


  <LinearLayout
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:visibility="visible"

      android:layout_marginVertical="5dp">


        <VerticalTextView
            android:id="@+id/tv_sub_category"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Sathyan"
            android:gravity="center"
            android:paddingVertical="1dp"
            android:maxLines="1"
            android:textSize="14sp"
            android:layout_marginVertical="10dp"
            android:textColor="@color/black"
            android:textStyle="bold"
        />


  </LinearLayout>

</layout>

但是在滚动时项目高度会降低。

这是滚动之前的内容:

enter image description here

滚动后:

enter image description here

您会看到最后3个项目的高度降低了,有些c

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)