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

时间:2017-12-20 06:49:18

标签: android android-layout android-linearlayout textview

RecyclerView内的FrameLayout(屏幕A)和maxLines=10内的maxLines(屏幕B),但都有android:isScrollContainer="false"

在RecyclerView中,textview只渲染10行,并忽略其他文本。

但是LinearLayout中的textview显示了10行,但允许用户滚动。

如何禁用滚动并仅显示使用android:enabled="false"设置的最大行数。

我已经尝试过,

  • {{1}} - 它不起作用

  • {{1}} - 它会禁用textview中的超链接点击

更新

我不想在RecyclerView中滚动文本视图,我想仅在LinearLayout中禁用滚动。

3 个答案:

答案 0 :(得分:1)

试过下面这行?

recyclerView.setNestedScrollingEnabled(false);

答案 1 :(得分:1)

像这样创建NoScrollTextView extends 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"/>

答案 2 :(得分:1)

只需在课堂上设置

 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" />