8

Próbuję użyć układu koordynatora z układem apletu, który zawiera fragment jako "przewijany widok". Fragment składa się z recyclerView i układ dolnej wyrównane trzymając przycisk, tak jak poniżej:Jak używać układu koordynatora z fragmentem jako "przewijanego widoku"

enter image description here

Jednak dolna sekcja jest domyślnie ukryty:

enter image description here

i tylko pokazuje się po przewinięciu.

Z mojej klasy działalności: Layout

@Override 
protected void onCreate(Bundle savedInstanceState) 
{ 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 

    TestFragment fragment = (TestFragment) getFragmentManager().findFragmentByTag("Test"); 
    if (fragment == null) 
     fragment = new TestFragment(); 

    getFragmentManager().popBackStack(); 

    FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction(); 

    fragmentTransaction.replace(R.id.fragment_container, fragment, "Test"); 
    fragmentTransaction.commit(); 
} 

aktywny:

<RelativeLayout 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.CoordinatorLayout 
     android:id="@+id/main_content" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical"> 

     <FrameLayout 
      android:id="@+id/fragment_container" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      app:layout_behavior="@string/appbar_scrolling_view_behavior"/> 

     <android.support.design.widget.AppBarLayout 
      android:id="@+id/appbar" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> 

      <android.support.design.widget.TabLayout 
       android:id="@+id/tabs" 
       android:layout_width="match_parent" 
       android:layout_height="?attr/actionBarSize" 
       app:layout_scrollFlags="enterAlways|scroll" 
       app:tabGravity="fill" 
       app:tabMode="fixed"/> 

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

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

</RelativeLayout> 

układ Fragment:

<RelativeLayout 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.v7.widget.RecyclerView 
     android:id="@+id/recyclerView" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_above="@+id/bottomView" 
     android:scrollbars="vertical" 
     android:visibility="visible"/> 

    <RelativeLayout 
     android:id="@+id/bottomView" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:background="#d4285d" 
     app:layout_scrollFlags="enterAlways"> 

     <Button 
      android:id="@+id/button" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Do something..." 
      android:textSize="14sp"/> 

    </RelativeLayout> 
</RelativeLayout> 

Koniec celem tutaj jest fragment mieć dolny pasek zawsze na ekranie, a widok recyklera przewija aplikację.

Czy to możliwe?

Dzięki!

+1

Mam ten sam problem. Połowę "rozwiązałem", umieszczając "bottomLayout" w działaniu (a nie w fragmencie) i poza obszarem CoordinatorLayout. Teraz pozostaje widoczny nawet podczas przewijania. Jednak czasami też chcę to ukryć (nie podczas przewijania, ale kiedy naciskam przycisk na pasku narzędzi), w takim przypadku widok przewijania (RecyclerView) nie wypełnia zapełnionego miejsca, zamiast tego pozostaje "pusty" (biały). Ponadto "bottomView" pojawia się na górze przewijanego widoku, mimo że znajduje się poza położeniem CoordinatorLayout, a pod nim w LinearLayout. Jestem zdezorientowany ... –

+0

Nick, na tym skończyłem, przyjmując to samo podejście, gdzie bottomLayout jest umieszczane w działaniu. Zajmowałem się tym w sposób ogólny, dodając FrameLayout do działania, do którego uzyskuję dostęp z tego fragmentu i dodaje tam widok. Jest brudny, ale nie mogłem tego obejść. Nie mam do czynienia z ukrywaniem tego paska czasami (poza ukrywaniem go całkowicie, gdy przełączam fragmenty), więc nie mogę komentować tego problemu ... przepraszam. – Zach

Odpowiedz

Powiązane problemy