问题
I am using three fragments in one activity with tablayout. In fragment I have 12 edittext so I put them into the scrollview.But scrolling is not working and I can see only few edittexts.
fragment.xml
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="1dp"
android:background="#fffbfbfb"
android:fillViewport="false"
android:id="@+id/scrollView">
<TableLayout
android:id="@+id/tableLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:stretchColumns="0"
android:background="#fffbfbfb">
........
</scrollview>
activity.xml
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabGravity="fill"
app:tabMode="fixed" />
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</android.support.design.widget.AppBarLayout>
</android.support.design.widget.CoordinatorLayout>
回答1:
If you are using scrollview inside coordinator layout, instead of using default scrollview, try using NestedScrollView
回答2:
try this in your code and make sure Scroll view have single child
<ScrollView
android:layout_height="fill_parent"
android:layout_width="wrap_content"
android:fillViewport="true"
android:isScrollContainer="false"
xmlns:android="http://schemas.android.com/apk/res/android" >
if still not work then wrap table layout in Linear Layout
回答3:
Ok I did one thing in fragment.java file:
scrollView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
scrollView.getParent().requestDisallowInterceptTouchEvent(true);
return false;
}
});
Now scrollview is working fine but viewpager has stopped working I mean I am not able to change fragment by horizontally touch as it was working before putting above method in fragment.java
来源:https://stackoverflow.com/questions/35448145/scrollview-inside-fragment-not-scrolling-at-all