android - 为什么 ScrollView 会自动滚动到屏幕底部?
问题描述
我想PreferenceFragmentCompat
在另一个片段(ProfileFragment)中使用。这是我的fragment_profile
布局:
<?xml version="1.0" encoding="utf-8"?>
<layout 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">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
style="@style/ToolbarStyle"
android:theme="@style/ToolbarStyle"
app:popupTheme="@style/ToolbarStyle"
app:title="@string/profile">
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/cash"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/ktpay_cash_top_margin"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/balance"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/black"
android:textStyle="bold"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/cash"
tools:text="23423" />
<TextView
android:id="@+id/tgSymbol"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/bottom_margin_tenge_symbol"
android:layout_marginLeft="@dimen/margin_left_tenge_symbol"
android:gravity="bottom"
android:text="@string/tenge_symbol"
app:layout_constraintBottom_toBottomOf="@+id/balance"
app:layout_constraintLeft_toRightOf="@+id/balance" />
<LinearLayout
android:id="@+id/wallet_recharge_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:clickable="true"
android:focusable="true"
android:foreground="?attr/selectableItemBackground"
android:orientation="horizontal"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/ktpay_balance">
<ImageView
android:id="@+id/wallet_icon"
android:layout_width="@dimen/wallet_icon_size"
android:layout_height="@dimen/wallet_icon_size"
android:src="@drawable/add_money" />
<TextView
android:id="@+id/recharge_wallet"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="@dimen/margin_left_from_wallet_icon"
android:text="@string/recharge"
android:textColor="@color/recharge_color" />
</LinearLayout>
<android.support.constraint.ConstraintLayout
android:id="@+id/bonus_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:background="@drawable/bonus_layout"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/wallet_recharge_layout">
<TextView
android:id="@+id/bonusText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:text="@string/bonuses_kt"
android:textColor="@color/black"
app:layout_constraintBottom_toTopOf="@+id/amount_bonus"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/amount_bonus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:textColor="@color/black"
android:textSize="@dimen/bonus_amount_text_size"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/bonusText"
tools:text="123213 тг" />
</android.support.constraint.ConstraintLayout>
<FrameLayout
android:id="@+id/appSettings"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/bonus_layout" />
</android.support.constraint.ConstraintLayout>
</ScrollView>
</LinearLayout>
我添加到我的FrameLayout
id扩展自. 一切都很好,除了加载时,它的内容已经滚动到屏幕底部。我不希望它发生。当我从中删除时,它按预期工作。但我需要。我认为可能的原因之一是使用. 它以某种方式影响我的 UI,因为现在包含包含. 我以为我需要在里面打电话,但不知道如何获得参考。那么,基本问题是为什么显示内部时会滚动到底部?这个问题的可能原因是什么?app_settings
SettingsFragment
PreferenceFragmentCompat
fragment_profile
ScrollView
fragment_profile
ScrollView
PreferenceFragmentCompat
RecyclerView
fragment_profile
ScrollView
RecyclerView
setNestedScrollingEnabled
RecyclerView
PreferenceFragmentCompat
RecyclerView
ScrollView
fragment_profile
解决方案
Scrollview 获得了对 Fragment 打开的关注。因此,为了确保它不会在片段打开时滚动,请将以下属性添加到 parent LinearLayout
。
android:focusableInTouchMode="true"
android:descendantFocusability="beforeDescendants"
推荐阅读
- python - 我该如何尝试:开发和生产之间除外?
- android - Flutter:未找到 MediaQuery 小部件祖先
- pandas - 计算到python中某些点的最近距离
- kubernetes - Kubernetes 中的 subPath 和 mountPath 有什么区别
- linear-search - 如何在 LinearSearch 中使用 Hoare-Logic 解决矛盾
- reactjs - Jest 获取未定义的标签元素
- python - parse:匹配字符串的中间部分
- android - Xamarin Forms - Android - 远程推送通知 - hub.Register(); 发布版本中的异常在调试中很好
- reactjs - 无效公式:/usr/local/Homebrew/Library/Taps/facebook/homebrew-fb/buck.rb
- vba - VBA Word:将字符样式应用于特定段落样式的前两个单词