【发布时间】:2017-05-11 04:35:53
【问题描述】:
我使用的是nestedscrollview,因为我在同一个Activity 中有recyclerview 和其他视图。我什至需要在列表和视图之间的同一活动中添加视图寻呼机。如果我将高度设置为 wrap_content,我看到视图寻呼机不占用任何空间。如果我对高度进行硬编码,它就会显示出来。我需要包装 viewpager,因为 pager 中的内容可能会增加或减少。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.neighboure.customer.activity.ProductDetailActivity"
tools:showIn="@layout/activity_product_detail">
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="@dimen/_10sdp">
<android.support.v7.widget.RecyclerView
android:id="@+id/productsimgrecycleview"
android:layout_width="match_parent"
android:layout_height="@dimen/_60sdp">
</android.support.v7.widget.RecyclerView>
<android.support.v4.view.ViewPager
android:id="@+id/des_spec_container"
android:layout_width="match_parent"
android:layout_height="180dp"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="@+id/btncart"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@color/lightgrey"
android:text="@string/label_add_to_cart"
android:textColor="@color/black"/>
</LinearLayout>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</RelativeLayout>
请参考以下截图
正如您在上图中所见,viewpager 中的内容是可见的,因为我已经硬编码了 view pager 的高度。
上图中,我已经包裹了viewpager,内容是不可见的。
提前致谢。
【问题讨论】:
-
将 NestedScrollView 的高度设置为 match_parent
-
还有 android:fillViewport="true"
-
我将 android:fillViewport="true" 应用于 NestedScrollView,现在它可以工作了。
标签: android android-viewpager android-nestedscrollview