0

Ich habe versucht, eine scrollbare Ansicht mit einer ViewPager machen, die 90% des Bildschirms und dann einige nützliche Informationen über Bilder innerhalb der ViewPager nehmen wird.Scrollview enthält Viewpager und ein Linearlayout

Allerdings, wenn ich das Widget ScrollView hinzufügen, funktionieren alle Größen und Gewicht nicht, auch wenn ich android:fillViewport="true" einstellen. Hier ist mein Layout. Entfernen

<?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

Bitte meine Antwort überprüfen und lassen Sie mich wissen, ob es funktioniert. Vielen Dank! –

+0

Machen Sie NestedScrollView match_parent und fügen Sie eine Eigenschaft fitSystemWindows = true zu Ihrem NestedScrollView –

+0

@MuhibPirani Es wirft einen Fehler: (2) Keine Ressource Kennung für Attribut 'fitSystemWindows' im Paket 'android' gefunden, auch wenn ich "compile 'com.android hinzufügen. Unterstützung: Design: 25.3.1 '"innen Gradle Skript –

Antwort

0

die android:fillViewport="true" und stellen Sie die layout_height Ihrer NestedScrollView-match_parent.

Also hier ist das endgültige Layout sollte wie folgt aussehen.

<?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

Danke. Aber das Problem ist: Wenn ich viele Ansichten nach dem linearen Layout hinzufüge, das den Viewpager umhüllt, reduziert der Viewpager seine Größe. –

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

Danke! Das Problem besteht immer noch, wenn ich dieses gute Layout in einem ScrollView hinzufügen –

+0

Fügen Sie es nicht in der Bildlaufansicht, nur in einer anderen XML-Datei testen ... Ich habe relative Layout mit 90 Viewpager teilen –

Verwandte Themen