我已经在互联网上搜索了此问题,但找不到解决方法。
我的main_activity布局中有4个选项卡,每个选项卡中我都显示一些信息,框架布局,并且里面有一个ScrollView,问题是滚动没有完全进行,滚动时还剩下一些信息
检查图像底部,滚动停止。
这是我的main_activity布局。
<?xml version="1.0" encoding="utf-8"?>
<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.v7.widget.Toolbar
android:id="@+id/tabanim_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
<android.support.design.widget.TabLayout
android:id="@+id/tabanim_tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabGravity="fill"
app:tabMode="fixed" />
</android.support.design.widget.AppBarLayout>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_marginRight="20dp"
android:layout_marginBottom="30dp"
android:background="@color/colorPrimary"
app:srcCompat="@drawable/ic_action_toggle_star" />
<android.support.v4.view.ViewPager
android:id="@+id/tabanim_viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</android.support.design.widget.CoordinatorLayout>
这是我的布局XML文件。
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="@color/material_grey"
android:orientation="vertical"
android:padding="@dimen/frame_layout_padding">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:animateLayoutChanges="true"
android:orientation="vertical"
android:padding="@dimen/padding">
<android.support.v7.widget.CardView
android:id="@+id/cardTreble"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:foreground="?android:attr/selectableItemBackground"
app:cardElevation="2dp"
app:cardUseCompatPadding="true">
<LinearLayout
android:id="@+id/cardTreble_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:id="@+id/cardTreble_header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="@dimen/padding">
<ImageView
android:id="@+id/trebleResult_image"
android:layout_width="@dimen/card_icon_size"
android:layout_height="@dimen/card_icon_size"
android:layout_gravity="center_vertical"
android:layout_marginRight="16dp"
app:srcCompat="@drawable/circle" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:orientation="vertical">
<TextView
style="@style/TextAppearance.AppCompat.Title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/title_treble_check"
android:textSize="@dimen/card_header_textsize" />
<TextView
android:id="@+id/trebleResult_title"
style="@style/TextAppearance.AppCompat.Subhead"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/result_pending"
android:textSize="@dimen/card_header_textsize" />
</LinearLayout>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/divider" />
<TextView
android:id="@+id/trebleResult_desc"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="@dimen/padding"
android:text="@string/result_pending" />
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:id="@+id/cardSeamless"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:foreground="?android:attr/selectableItemBackground"
app:cardElevation="2dp"
app:cardUseCompatPadding="true">
<LinearLayout
android:id="@+id/cardSeamless_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:id="@+id/cardSeamless_header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="@dimen/padding">
<ImageView
android:id="@+id/seamlessResult_image"
android:layout_width="@dimen/card_icon_size"
android:layout_height="@dimen/card_icon_size"
android:layout_gravity="center_vertical"
android:layout_marginRight="16dp"
app:srcCompat="@drawable/circle" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:orientation="vertical">
<TextView
style="@style/TextAppearance.AppCompat.Title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/seamless_title"
android:textSize="@dimen/card_header_textsize" />
<TextView
android:id="@+id/seamlessResult_title"
style="@style/TextAppearance.AppCompat.Subhead"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/result_pending"
android:textSize="@dimen/card_header_textsize" />
</LinearLayout>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/divider" />
<TextView
android:id="@+id/seamlessResult_desc"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="@dimen/padding"
android:text="@string/result_pending" />
<Button
android:id="@+id/seamlessResult_more"
style="@style/Widget.AppCompat.Button.Borderless"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/button_margin"
android:text="@string/card_learnmore" />
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:id="@+id/cardTrebleInfo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:foreground="?android:attr/selectableItemBackground"
app:cardElevation="2dp"
app:cardUseCompatPadding="true">
<LinearLayout
android:id="@+id/cardTrebleInfo_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:id="@+id/cardTrebleInfo_header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="@dimen/padding">
<ImageView
android:layout_width="@dimen/card_icon_size"
android:layout_height="@dimen/card_icon_size"
android:layout_gravity="center_vertical"
android:layout_marginRight="16dp"
android:src="@drawable/ic_treble" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:orientation="vertical">
<TextView
style="@style/TextAppearance.AppCompat.Title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/treble_info_title"
android:textSize="@dimen/card_header_textsize" />
<TextView
style="@style/TextAppearance.AppCompat.Subhead"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/treble_info_subhead"
android:textSize="@dimen/card_header_textsize" />
</LinearLayout>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/divider" />
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:src="@drawable/treble_banner_before" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="@dimen/padding"
android:text="@string/treble_info_1" />
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:src="@drawable/treble_banner_after" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="@dimen/padding"
android:text="@string/treble_info_2" />
<Button
android:id="@+id/trebleInfo_more"
style="@style/Widget.AppCompat.Button.Borderless"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/button_margin"
android:text="@string/card_learnmore" />
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
</ScrollView>
</FrameLayout>
答案 0 :(得分:0)
在 ScrollView
中使用以下内容android:fillViewport="true"
并将其高度设置为 match_parent
因为要滚动 ScrollView ,必须先设置高度,然后才能开始滚动视图。
更新
使用如下的customcrollview:
public class CustomScrollView extends ScrollView {
private GestureDetector mGestureDetector;
public CustomScrollView(Context context, AttributeSet attrs) {
super(context, attrs);
mGestureDetector = new GestureDetector(context, new YScrollDetector());
setFadingEdgeLength(0);
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
return super.onInterceptTouchEvent(ev) && mGestureDetector.onTouchEvent(ev);
}
// Return false if we're scrolling in the x direction
class YScrollDetector extends SimpleOnGestureListener {
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
return Math.abs(distanceY) > Math.abs(distanceX);
}
}
}
更新2
使用 android.support.v4.widget.NestedScrollView 而不是ScrollView