【问题标题】:Android ScrollView below Toolbar fails to show all content工具栏下方的 Android ScrollView 无法显示所有内容
【发布时间】:2015-08-07 22:41:48
【问题描述】:

我使用工具栏创建了一个基本活动并将我的布局添加到其中。但是当我在主要内容中添加滚动视图时,向下滚动时它不会显示底部。缺少的部分似乎与工具栏的高度相同。

我的activitybase.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical">
    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        style="@style/ToolBarStyle"
        android:background="?attr/colorPrimary" />
    <FrameLayout
        android:id="@+id/root_container"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1" />
</LinearLayout>

我的 fragmentinfo.xml:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:fillViewport="true">
    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="@dimen/default_margin">
        <TextView
            android:id="@+id/info_header"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="@dimen/default_margin"
            android:text="hei"
            style="@style/TextLarge" />
        <TextView
            android:id="@+id/info_text"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="@dimen/small_margin"
            android:text="-SOME LONG TEXT-"
            style="@style/TextNormal" />

      <TextView
            android:id="@+id/info_header2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="@dimen/default_margin"
            android:text="Test"
            style="@style/TextLarge" />
    </LinearLayout>
</ScrollView>

截图如下。这是一直向下滚动的。 “测试”应显示在其下方 16 dp 边距...

【问题讨论】:

  • TextView 添加android:paddingBottom="20dp"
  • 谢谢。这至少适用于更大的填充,但我仍然不知道为什么 ScollView 会切断其内容的底部。

标签: android scrollview toolbar


【解决方案1】:

在框架布局中

<FrameLayout
  ...
  android:layout_marginBottom="56dp"
  ...
/>

这里 56dp 是操作栏的大小。

【讨论】:

  • 感谢您的回答。但这会给我所有页面的下边距。向下滚动时,问题仅出现在一个滚动视图中。
【解决方案2】:

使用操作栏高度维度将 android:layout_marginBottom 添加到 ScrollView。

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginBottom="@dimen/abc_action_bar_default_height_material"
    android:fillViewport="true">

【讨论】:

  • 我认为是“android:layout_marginTop”
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-08-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多