【问题标题】:Android NestedScrollView ViewPager wrap_contentAndroid NestedScrollView ViewPager wrap_content
【发布时间】: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,内容是不可见的。

提前致谢。

【问题讨论】:

标签: android android-viewpager android-nestedscrollview


【解决方案1】:
 NestedScrollView scrollView = (NestedScrollView) findViewById (R.id.nest_scrollview);
    scrollView.setFillViewport (true);

你可以看到ViewPager in a NestedScrollView

【讨论】:

    【解决方案2】:

    可以考虑更换

    android:layout_height="wrap_content"
    

    结合

    android:layout_height="0dp"
    android:layout_weight="1"
    

    TextView below NestedScrollView with height wrap_content not visible

    【讨论】:

      猜你喜欢
      • 2018-05-14
      • 2012-01-13
      • 1970-01-01
      • 1970-01-01
      • 2021-03-10
      • 1970-01-01
      • 2020-04-28
      • 1970-01-01
      相关资源
      最近更新 更多