0

Ich habe fragment, die cointains toolbar nicht hat. Toolbar muss in activity bleiben. Diese fragment muss Haupt view und unter viewpager mit zwei fragments zeigen. Jeder fragment ist spezifisch. Erste Verwendung benutzerdefinierte layout, zweite Verwendung adapter. Jeder hat unterschiedliche Höhe. Ich habe viele libs und Ideen ausprobiert, aber keiner von ihnen funktioniert so, wie es sollte (es machte scroll länger/kürzer als es sollte oder es machte verrückt UI Overlays).Wie man einen View Container über Viewpager "scrollbar" macht (Toolbar ist in Activity, nicht Fragment)?

Ich versuche UI zu tun, wo es aussieht, dass das alles eins ist layout, das heißt, es ist von oben nach unten scrollbar. Aber ich kann es nicht herausfinden. Ich dachte daran, CoordinatorLayout zu verwenden, aber ich habe keine Ahnung, wie.

XML:

<?xml version="1.0" encoding="utf-8"?> 
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/main_content" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="200dp" 
     android:background="#FF0000" 
     android:orientation="vertical"> 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:text="ABCDEFGH" /> 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:text="GHIKJ" /> 

    </LinearLayout> 

    <android.support.v4.view.ViewPager 
     android:id="@+id/viewPager" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior" /> 

</android.support.design.widget.CoordinatorLayout> 

Wie man dies als scrollbare layout in fragment ohne toolbar Referenzen zu verwenden?

Update: Ja, hier sind ein paar Bilder, ich hoffe es ist jetzt klarer. enter image description here

+0

Können Sie zeigen Sie Ihren gewünschten Bildschirm? Was willst du wirklich erreichen? –

+0

Ja, bitte überprüfen Sie die Bilder. – Michalsx

Antwort

0

Wickeln Sie Ihre LinearLayout innerhalb eines AppBarLayout. Eigentlich AppBarLayout erweitert LinearLayout so können Sie einfach Ihre LinearLayout damit ersetzen.

Auch wenn Ihre App keine Symbolleiste oder App-Leiste hat, ist die AppBarLayout die Ansicht, die mit CoordinatorLayout koordiniert wird.

Das Hinzufügen der AppBarLayout sollte das Verhalten, das Sie suchen, bereitstellen.

+0

So kann ich mehr AppBarLayouts haben? Weil ich schon eins in der Haupttätigkeit habe? – Michalsx

+0

Oh, die Frage noch einmal gelesen, jetzt sehe ich dein Problem. Bitte veröffentlichen Sie das Layout-XML für Ihre Aktivität. –

0

Dieses Wurzelfragment-Layout scheint zu funktionieren. Ich bin mir nicht sicher, ob das die beste Lösung ist, aber es funktioniert.

Hinweis: Ich habe Listview durch Standard LinearLayout als Root-Container ersetzt und untergeordnete Layouts (Elemente) dort aufblasen.

<?xml version="1.0" encoding="utf-8"?> 
<android.support.design.widget.CoordinatorLayout 
    android:id="@+id/main_content" 
    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.support.design.widget.AppBarLayout 
     android:layout_width="match_parent" 
     android:layout_height="250dp" 
     android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> 

     <android.support.design.widget.CollapsingToolbarLayout 
      android:id="@+id/collapsing_toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      app:layout_scrollFlags="scroll|enterAlways"> 

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

      </LinearLayout> 

     </android.support.design.widget.CollapsingToolbarLayout> 

    </android.support.design.widget.AppBarLayout> 

    <android.support.v4.view.ViewPager 
     android:id="@+id/viewPager" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior"/> 

</android.support.design.widget.CoordinatorLayout> 

Child-Fragment (für viewpager):

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v4.widget.NestedScrollView 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <LinearLayout 
     android:id="@+id/childFragment" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical"/> 

</android.support.v4.widget.NestedScrollView> 
Verwandte Themen