我一直在关注这个项目,使用Android Hive标签进行材料设计。
现在我正在尝试在片段中添加ScrollView。该片段将添加到ViewPager中。但它没有显示ScrollView中内容的最后+ -50 dp。我认为它在layout_height属性中的某个地方,但我不知道如何解决这个问题。
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: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/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/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabMode="fixed"
app:tabGravity="fill"/>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</android.support.design.widget.CoordinatorLayout>
Fragment_one.xml:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/scroll"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
tools:context="com.a42.pthong.philips.CompanyFragment">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_margin="@dimen/activity_horizontal_margin"
android:orientation="vertical">
<TextView
android:text="@string/title"
android:id="@+id/textView"
android:textSize="20sp"
android:textStyle="bold"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/content1"
android:text="@string/content"
android:textSize="12sp"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</ScrollView>
答案 0 :(得分:4)
这是因为您将CoordinatorLayout
与ScrollView
一起使用。将您的实施更改为android.support.v4.widget.NestedScrollView
以实现正确的滚动。
CoordinatorLayout滚动适用于NestedScrollingChild的孩子。
我回答了here同样的问题。