2017-01-15 2 views
0

Ich habe den folgenden Xml-Code, wo ich den Inhalt eines Fragments in FrameLayount anzeigen möchte, aber ich weiß nicht, wie ich meine Schaltfläche immer unten halten.Android-Taste dauerhaft unten

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:id="@+id/activity_lista_preguntas" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="vertical" 
tools:context="com.ingenierovagabundo.encuestafacil.GUI.ListaPreguntasActivity"> 

<!-- Toolbar --> 
<android.support.v7.widget.Toolbar xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/appbar_nueva_pregunta" 
    android:layout_width="match_parent" 
    android:layout_height="?attr/actionBarSize" 
    android:background="?attr/colorPrimary" 
    android:elevation="4dp" 
    android:minHeight="?attr/actionBarSize" 
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" 
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light" /> 

<FrameLayout 
    android:id="@+id/contenedor_Pregunta" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"> 

</FrameLayout> 

<Button 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_gravity="bottom|right" 
    android:layout_marginBottom="16dp" 
    android:layout_marginRight="16dp" 
    android:text="@string/npa_button_guardar"/> 

Antwort

0

Sie android:layout_weight="1" zu Ihrem FrameLayout hinzufügen könnte. Dadurch wird die FrameLayout erweitert, um verbleibenden Platz in der übergeordneten Ansicht zu füllen. Was dazu führen sollte, dass der Button ganz unten ist. Ihre resultierende FrameLayout wird also sein,

<FrameLayout 
    android:id="@+id/contenedor_Pregunta" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_weight="1"> 

</FrameLayout> 

Weitere Informationen über layout_weight folgen Sie dem Link https://developer.android.com/guide/topics/ui/layout/linear.html#Weight

0

Sie verwenden ein LinearLayout als Container, dann die Elemente aufeinander folgen.

Wenn Sie Ihre Taste immer unten halten möchten, verwenden Sie eine RelativeLayout mit android:layout_alignParentBottom="true".

Sie müssen auch Ihren Container schließen! ;)

0

Verwenden Sie diesen Code in activity_main.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" 
     xmlns:tools="http://schemas.android.com/tools" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:fitsSystemWindows="true"> 

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

     <include layout="@layout/content_main" /> 

     <Button 
      android:id="@+id/button" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="bottom|end" 
      android:layout_margin="@dimen/fab_margin" 
      app:backgroundTint="@color/colorOrange" 
      app:srcCompat="@android:drawable/ic_menu_share" 
      tools:ignore="VectorDrawableCompat" /> 

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

Und in content_main.xml, diesen Code verwenden.

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 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:id="@+id/content_main" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:showIn="@layout/app_bar_main"> 

    <FrameLayout 
     android:id="@+id/frame_container" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"/> 
</RelativeLayout> 
1

können Sie RelativeLayout Einsatz von Linearlayout insted wie folgt:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:id="@+id/activity_lista_preguntas" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="vertical" 
tools:context="com.ingenierovagabundo.encuestafacil.GUI.ListaPreguntasActivity"> 

<!-- Toolbar --> 
<android.support.v7.widget.Toolbar xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/appbar_nueva_pregunta" 
    android:layout_width="match_parent" 
    android:layout_height="?attr/actionBarSize" 
    android:background="?attr/colorPrimary" 
    android:elevation="4dp" 
    android:minHeight="?attr/actionBarSize" 
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" 
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light" /> 

<FrameLayout 
    android:id="@+id/contenedor_Pregunta" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_above="@+id/btn" 
    android:layout_below="@+id/appbar_nueva_pregunta"> 

</FrameLayout> 

<Button 
    android:id="@+id/btn" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="false" 
    android:layout_marginBottom="16dp" 
    android:layout_marginRight="16dp" 
    android:text="@string/npa_button_guardar" />