【发布时间】:2017-04-19 17:04:09
【问题描述】:
我尝试使用ViewPager 制作一个可滚动的视图,这将占据屏幕的 90%,然后是ViewPager 中有关图像的一些有用信息。
但是,当我添加 ScrollView 小部件时,即使我设置了 android:fillViewport="true",所有尺寸和重量都不起作用。这是我的布局。
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView
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="wrap_content"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:weightSum="100"
android:scrollbars="vertical">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/background_light"
android:elevation="0dp"
android:minHeight="?attr/actionBarSize"
android:theme="?attr/actionBarTheme"
app:popupTheme="?android:attr/homeAsUpIndicator" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="90"
android:orientation="vertical"
android:padding="50dip">
<android.support.v4.view.ViewPager
android:id="@+id/product_sheet_viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
<TextView
android:id="@+id/product_sheet_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="bbb"/>
<TextView
android:id="@+id/product_sheet_color"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Color: Yellow" />
<TextView
android:id="@+id/product_sheet_reference"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Ref: 2049/889/300" />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
【问题讨论】:
-
请检查我的答案,让我知道它是否有效。谢谢!
-
使 NestedScrollView match_parent 并为您的 NestedScrollView 添加一个属性 fitSystemWindows=true
-
@MuhibPirani 它会引发错误:(2) 即使我添加了“compile 'com.android.support:design:25.3.1 '" 在 gradle 脚本中
-
@ReazMurshed 谢谢。但问题是:当我在包装 viewpager 的线性布局之后添加大量视图时,viewpager 会减小其大小。就像nestedscrollview 有一个固定的高度,然后不支持滚动移动。但是,viewpager 必须覆盖 90% 的屏幕。
标签: android android-layout android-fragments android-viewpager android-scrollview