Sto utilizzando il layout di seguito, Il CoordinatorLayout
tiene al suo interno AppBarLayout
(Con Toolbar
e TabLayout
al suo interno) e un segnaposto RelativeLayout
, così ho potuto aggiungere e sostituire i frammenti su di esso.CoordinatorLayout con Toolbar e frammento
Sto riscontrando errori di margine, i frammenti che aggiungo su RelativeLayout si espandono sempre oltre la parte inferiore dello schermo (nella quantità simile alla dimensione dell'altezza AppBarLayout
), ho provato a impostare l'altezza a wrap_content
e match_parent
, in entrambi i casi va in mare.
se rimuovo app:layout_behavior="@string/appbar_scrolling_view_behavior"
da RelativeLayout
la parte superiore di esso sarà sotto il AppBarLayout
che non è anche il risultato desiderato.
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_layout"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:fitsSystemWindows="true">
<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">
<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.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:layout_scrollFlags="scroll|enterAlways" />
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
app:tabIndicatorHeight="4dp"
app:tabIndicatorColor="#ffffff"
app:tabMode="scrollable"
android:visibility="gone"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</android.support.design.widget.AppBarLayout>
<RelativeLayout
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:id="@+id/main_fragment_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:layout_margin="20dp"
android:src="@drawable/ic_done" />
</android.support.design.widget.CoordinatorLayout>
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_height="match_parent"
android:layout_width="wrap_content"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header"
app:menu="@menu/drawer_view"/>
</android.support.v4.widget.DrawerLayout>
Puoi fare un esempio migliore? Quel 'RelativeLayout' non fa nulla e ha un'altezza tecnicamente' 0' a causa di 'wrap_content' a meno che tu non stia facendo qualcosa con esso a livello di programmazione. Se vuoi usarlo come 'containter', usa un' FrameLayout'. –
Inserisco un frammento su di esso, eseguo una transazione di frammento e fornisco l'id di RelativeLayout, ho anche provato a utilizzare FrameLayout stesso risultato. – Calc
È ovvio che tu l'abbia preso dall'esempio di Chris Banes: https://github.com/chrisbanes/cheesesquare/blob/master/app/src/main/res/layout/include_list_viewpager.xml. Si noti che il suo 'ViewPager' usa' match_parent'? –