【问题标题】:ScrollView in tabbed activity jumps down选项卡式活动中的 ScrollView 跳下
【发布时间】:2017-04-02 22:07:42
【问题描述】:

我正在制作一个 xkcd 解释阅读器应用程序。

我从一个由想法预先生成的选项卡式活动开始。然后我将片段的 xml 更改为滚动视图,其中包含我的实际布局。

然而事情并没有完全按预期工作,每次我切换到另一个选项卡(/片段)时,它都会正确呈现,但一秒钟后我的滚动视图会向下跳一点(滚动条不是实际的滚动视图)。

动作图:Android screen capture showing the issue

如果需要任何额外的信息,请告诉我。

编辑:有些人建议将滚动视图更改为嵌套滚动视图。这并没有解决我的问题。

片段的 xml:

<ScrollView
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        tools:context="com.henrykvdb.xkcdexplain.MainActivity$PlaceholderFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/scrollView"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin"
        android:paddingBottom="@dimen/activity_vertical_margin"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">
    <LinearLayout
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center_horizontal">
        <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceLarge"
                android:text="Title"
                android:id="@+id/titleTextView"
                android:textStyle="bold"/>
        <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:text="Desc"
                android:id="@+id/descTextView"/>
        <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/imageView"
                android:contentDescription="xkcd"/>
        <WebView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/explainWebView"
                android:layout_below="@+id/imageView"/>
    </LinearLayout>
</ScrollView>

我的 activity_main 的 xml:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/main_content"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context="com.henrykvdb.xkcdexplain.MainActivity">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingTop="@dimen/appbar_padding_top"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:popupTheme="@style/AppTheme.PopupOverlay"
            app:layout_scrollFlags="scroll|enterAlways">

        </android.support.v7.widget.Toolbar>

    </android.support.design.widget.AppBarLayout>

    <android.support.v4.view.ViewPager
        android:id="@+id/container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="end|bottom"
        android:layout_margin="@dimen/fab_margin"
        android:src="@android:drawable/ic_dialog_email" />

</android.support.design.widget.CoordinatorLayout>

【问题讨论】:

  • 仅供参考,我尝试将您的图片添加到帖子中,但由于它是 GIF,因此显示为损坏的图片。
  • 好吧,不知道我不能使用 gif。我对 stackoverflow 还是很陌生。

标签: android xml layout scrollview android-tabbed-activity


【解决方案1】:

android:descendantFocusability="blocksDescendants" 添加到我的LinearLayout 修复了所有问题。

【讨论】:

  • 我还不能接受。自己发布答案后,有 24 小时的冷却时间才能接受。 @ToddSewell
  • 未完全修复,但添加此建议后有一点改进。
猜你喜欢
  • 1970-01-01
  • 2016-03-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-22
  • 1970-01-01
相关资源
最近更新 更多