1

J'ai codé un fragment simple qui couple des vues de texte et un bouton, le tout dans un RelativeLayout.RelativeLayout ne dessine pas correctement avec la mise en page de coordinateur android

<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" 
       tools:context=".fragments.TutorialFragment"> 

    <TextView 
     android:id="@+id/tuto_title" 
     style="?android:textAppearanceLarge" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 

     android:padding="20dp" 
     android:text="@string/tutorial_title"/> 

    <TextView 
     android:id="@+id/tuto_msg" 
     style="?android:textAppearanceLarge" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@id/tuto_title" 
     android:padding="20dp" 
     android:text="@string/tutorial_txt"/> 

    <Button 
     android:id="@+id/nextBtn" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_margin="15dp" 
     android:text="@string/next"/> 

</RelativeLayout> 

Ce fragment affiche grand sur le StudioDesigner, mais lors de l'exécution du code du titre est manquant AVD Running

La mise en page d'activité est

<?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" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:fitsSystemWindows="true" 
android:id="@+id/coordinatorLayout" 
tools:context="com.crocodil.software.a1ccalc.A1CActivity"> 

<android.support.design.widget.AppBarLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:theme="@style/AppTheme.AppBarOverlay"> 

    <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/AppTheme.PopupOverlay"/> 

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


<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      android:id="@+id/fragment_container" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" /> 

Il semble que le calcule fragment son espace disponible avant que la barre d'outils ne soit placée ...

Voici l'écran que je vois dans le concepteur

Designer

Merci pour toutes les indications

+0

C'est correct de cours. Cependant, il est ennuyeux que le concepteur affiche l'écran différemment l'AVD ou un périphérique réel. Cela rend le débogage beaucoup plus difficile. – Croc

Répondre

2

Le problème est que le FrameLayout se trouve derrière la barre d'outils, le principal moyen d'ajouter une vue à l'intérieur de la mise en page de coordinateur qui a une barre d'outils est soit définir un margin ou ajouter app:layout_behavior="@string/appbar_scrolling_view_behavior" au Framelayout

<?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" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:fitsSystemWindows="true" 
android:id="@+id/coordinatorLayout" 
tools:context="com.crocodil.software.a1ccalc.A1CActivity"> 

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      android:id="@+id/fragment_container" 
      android:layout_width="match_parent" 
      android:layout_marginTop="?attr/actionBarSize" 
      android:layout_height="match_parent" /> 

<android.support.design.widget.AppBarLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:theme="@style/AppTheme.AppBarOverlay"> 

    <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/AppTheme.PopupOverlay"/> 

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

Prenez cet attribut

app:layout_behavior="@string/appbar_scrolling_view_behavior" 

et le mettre sur le fragment_container FrameLayout.