滚动视图不能在视图分页片段内工作



我在一个片段中使用滚动视图,这是在一个视图页内使用。但是滚动条似乎不起作用。

 <ScrollView
      android:id="@+id/scrollview"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      >
    <android.support.percent.PercentRelativeLayout
        android:id="@+id/container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        >
...
...
...
</android.support.percent.PercentRelativeLayout>
</ScrollView>

这是片段的布局。但是滚动似乎根本不起作用

try this

scrollview.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            v.getParent().requestDisallowInterceptTouchEvent(true);
            return false;
        }
    });

你可以尝试在"scrollview"及其子视图中使用"wrap_parent":

android: layout_height = " wrap_parent "

让滚动视图顶部(即父视图)填充父视图的高度和宽度

像下面这样使用NestedScrollView:

<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/scroll"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context=".FragmentContactInfo">
    <LinearLayout
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:orientation="vertical">
    </LinearLayout>
</android.support.v4.widget.NestedScrollView>

最新更新