gpt4 book ai didi

android - FrameLayout 中的 ScrollView 的问题

转载 作者:行者123 更新时间:2023-11-30 05:10:16 25 4
gpt4 key购买 nike

我已经在互联网上搜索过这个问题,但找不到解决方案。

我的 main_activity 布局中有 4 个选项卡,在每个选项卡中我都显示一些信息,我有框架布局,里面有一个 ScrollView ,问题是滚动没有完全发生,滚动时留下了一些信息.

检查图像底部,滚动停止。

Scrolling stopped

这是我的 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>

最佳答案

在您的 ScrollView 中使用 below

android:fillViewport="true"

并将其高度设置为ma​​tch_parent

因为要滚动,ScrollView 必须需要一个高度,超过该高度后它将开始 ScrollView 。

更新

像下面这样使用 customscrollview:

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

关于android - FrameLayout 中的 ScrollView 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53863527/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com