0

我試圖製作一個可滾動的視圖,其中一個ViewPager將佔用屏幕的90%,然後是有關ViewPager內部圖像的一些有用信息。Scrollview包含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> 
+0

請檢查我的答案,讓我知道,如果它的工作原理。謝謝! –

+0

使NestedScrollView match_parent並添加一個屬性fitSystemWindows = true到您的NestedScrollView –

+0

@MuhibPirani它引發錯誤:(2)沒有資源標識符找到屬性'fitSystemWindows'包'android',即使我添加「編譯」com.android。支持:設計:內嵌gradle腳本的25.3.1'「 –

回答

0

取出android:fillViewport="true"並設置NestedScrollViewmatch_parentlayout_height

所以這裏的最終佈局應該看起來像。

<?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="match_parent" 
    android:fillViewport="true"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" 
     android:scrollbars="vertical" 
     android:weightSum="100"> 

     <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> 
+0

謝謝。但問題是:當我在包裝viewpager的線性佈局之後添加大量視圖時,viewpager會減小其大小。 –

0
<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       xmlns:tools="http://schemas.android.com/tools" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 

    > 

    <RelativeLayout 
     android:id="@+id/relativeLayout" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:paddingBottom="5dp" 
     android:paddingTop="5dp" 
     android:layout_above="@+id/relativeLayoutBottom" 
     > 
     <android.support.v4.view.ViewPager 
      android:id="@+id/viewPagerPlanDetailBroucher" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:columnWidth="250dp" 
      android:numColumns="auto_fit" 
      android:verticalSpacing="1dp" 
      android:horizontalSpacing="1dp" 
      android:layout_marginRight="50dp" 
      android:layout_marginLeft="50dp" 
      > 
     </android.support.v4.view.ViewPager> 
     </RelativeLayout> 

    <RelativeLayout 
     android:id="@+id/relativeLayoutBottom" 
     android:layout_alignParentBottom="true" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:paddingBottom="5dp" 

     android:paddingTop="5dp" 
     > 
     <TextView 
      android:id="@+id/product_sheet_description" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_centerHorizontal="true" 
      android:text="bbb"/> 

     <TextView 
      android:id="@+id/product_sheet_color" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_centerHorizontal="true" 
      android:layout_below="@+id/product_sheet_description" 
      android:text="Color: Yellow" /> 

     <TextView 
      android:id="@+id/product_sheet_reference" 
      android:layout_below="@+id/product_sheet_color" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_centerHorizontal="true" 
      android:text="Ref: 2049/889/300" /> 

    </RelativeLayout> 
</RelativeLayout> 
+0

謝謝!當我在ScrollView中添加這個好的佈局時,問題仍然存在 –

+0

不要將它添加到滾動視圖中,只是在另一個XML文件中測試它......我已經將相對佈局與90 viewpager –

相關問題