Android:为什么TextView中的文本在LinearLayout中滚动,而不是在Recyclerview中滚动

Android:为什么TextView中的文本在LinearLayout中滚动,而不是在Recyclerview中滚动,android,android-layout,android-linearlayout,textview,Android,Android Layout,Android Linearlayout,Textview,在RecyclerView(屏幕A)和FrameLayout(屏幕B)内部都有TextView,但两者都有maxLines=10 在RecyclerView中,textview仅渲染10行,其他文本将被忽略 但LinearLayout中的文本视图显示10行,但允许用户滚动 如何禁用滚动并仅显示使用maxLines设置的最大行数 我已经试过了 android:isScrollContainer=“false”-它不工作 android:enabled=“false”-它禁用文本视图中的超链接单击

RecyclerView
(屏幕A)和
FrameLayout
(屏幕B)内部都有
TextView
,但两者都有
maxLines=10

在RecyclerView中,textview仅渲染10行,其他文本将被忽略

但LinearLayout中的文本视图显示10行,但允许用户滚动

如何禁用滚动并仅显示使用
maxLines
设置的最大行数

我已经试过了

  • android:isScrollContainer=“false”
    -它不工作

  • android:enabled=“false”
    -它禁用文本视图中的超链接单击

更新:

我不想在RecyclerView中滚动textview,我只想在LinearLayout中禁用滚动。

是否尝试了下面的一行

recyclerView.setNestedScrollingEnabled(false);
试过下面这句话吗

recyclerView.setNestedScrollingEnabled(false);

创建一个
NoScrollTextView
扩展
TextView
如下:

public class NoScrollTextView extends TextView {
    public NoScrollTextView(Context context) {
        super(context);
    }

    public NoScrollTextView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public NoScrollTextView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
    public NoScrollTextView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
    }

    @Override
    public void scrollTo(int x, int y) {
        //do nothing
    }
}
然后在xml中将其用作:

<com.example.NoScrollTextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:maxLines="10"/>

创建一个
NoScrollTextView
扩展
TextView
如下:

public class NoScrollTextView extends TextView {
    public NoScrollTextView(Context context) {
        super(context);
    }

    public NoScrollTextView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public NoScrollTextView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
    public NoScrollTextView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
    }

    @Override
    public void scrollTo(int x, int y) {
        //do nothing
    }
}
然后在xml中将其用作:

<com.example.NoScrollTextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:maxLines="10"/>

刚在课堂上设置好

 TextView tv = (TextView) view.findViewById(R.id.tv);
  tv.setMovementMethod(null);
在布局上

              <TextView
                android:id="@+id/tv"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="3dp"
                android:maxLines="8"
                android:text="Lorem Ipsum is simply dummy text of the dummy text of t printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy."
                android:textSize="14sp" />

刚在课堂上设置好

 TextView tv = (TextView) view.findViewById(R.id.tv);
  tv.setMovementMethod(null);
在布局上

              <TextView
                android:id="@+id/tv"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="3dp"
                android:maxLines="8"
                android:text="Lorem Ipsum is simply dummy text of the dummy text of t printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy."
                android:textSize="14sp" />


是的,我也尝试过这个方法,只是在寻找其他更好的方法,只是通过修改或设置视图属性而不是创建自定义视图。请不要复制粘贴相同的答案。是的,我也尝试过这个方法,只是在寻找其他更好的方法,只需修改或设置视图属性,而不是创建自定义视图。请不要复制粘贴相同的答案在这里,我已对其进行了修改。在此处添加要禁用滚动的xml。在此处添加要禁用滚动的xml。