【问题标题】:Android Scroll View in fragment crops content片段作物内容中的Android Scroll View
【发布时间】:2016-07-27 15:10:49
【问题描述】:

我创建了一个滚动视图,它应该允许我滚动浏览线性布局内的所有内容(即滚动视图的子视图)。

代码如下:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="pl.oakfusion.delegator.DomesticDelegationSecondFragment">

<LinearLayout
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    ....

    <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginRight="25dp"
        android:layout_marginTop="25dp"
        android:background="@color/textDarkest"
        android:text="Save"
        android:textColor="@color/textColor"
        android:layout_gravity="right" />
</LinearLayout>

预览看起来像这样:

但在我的应用中我有这个:

我无法向下滚动,我只能看到这些。

如果我允许旋转,我有水平视图:

现在允许我滚动但完全切断按钮。 (在图片上是视图的底部)我可以快速下拉,我可以看到按钮在那里但它又上升了(这个 android 的东西当你可以稍微拉远但它会向后滚动)

我该如何解决这个问题?

托管活动:

<?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"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="pl.oakfusion.delegator.DomesticDelegationActivity">

<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:layout_scrollFlags="scroll|enterAlways"
        app:popupTheme="@style/AppTheme.PopupOverlay">

    </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" />

【问题讨论】:

  • 您的活动布局如何(xml)?您是否使用像这里 stackoverflow.com/questions/31709100/… 这样的 CoordinatorLayout ?
  • 请分享您的完整 xml,并托管布局(如果有)以纠正问题。
  • 对,更新帖子

标签: android android-fragments android-scrollview


【解决方案1】:

尝试将此添加到您的 xml 布局中的滚动视图中

android:fillViewport="true"

【讨论】:

  • 如果你把它设置为假?对于许多人来说,这应该可以解决问题
【解决方案2】:

我曾经遇到过同样的问题。我尝试为 ScrollView 中的 ViewGroup 添加填充。然后它工作得很好。这是一个 hacky 解决方案,而不是理想的解决方案。

对于上面提到的示例(由 user3212350 提供): 我在 ScrollView 内的 LinearLayout 中添加了一些填充,以使视图完全可见。对于不同的屏幕尺寸,所需的填充量可能会有所不同。

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="pl.oakfusion.delegator.DomesticDelegationSecondFragment">

    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"

        ##android:paddingBottom="50dp"##>

        ....

        <Button
            android:id="@+id/button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginRight="25dp"
            android:layout_marginTop="25dp"
            android:background="@color/textDarkest"
            android:text="Save"
            android:textColor="@color/textColor"
            android:layout_gravity="right" />
    </LinearLayout>

【讨论】:

  • 你能加一段代码来解释一下你是怎么做的吗?
  • @JosephBudin 我添加了一些代码让您更好地了解我是如何解决这个问题的。替代解决方案是您可以在末尾添加一个虚拟文本视图,文本颜色与背景颜色相同(使其不可见)以获得相同的效果。同样,这也是一个 hacky 解决方案,而不是理想的解决方案
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多