2017-01-15 10 views
0

私は、FrameLayountにフラグメントのコンテンツを表示したいところで、次のXmlコードを持っていますが、私のボタンを常に下に保つ方法はわかりません。あなたはコンテナとしてLinearLayoutを使用Androidボタンが永久に底にある

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

答えて

0

をあなたのFrameLayoutandroid:layout_weight="1"を追加することができます。親ビューの残りのスペースを埋めるようにFrameLayoutを展開します。これはボタンが底に来るようにするはずです。 だからあなたの結果でframeLayoutはリンク https://developer.android.com/guide/topics/ui/layout/linear.html#Weight

に従って、 layout_weightの詳細について

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

</FrameLayout> 

になります

0

、その後の要素がお互いに従ってください。

ボタンを常に下に置いておきたい場合は、RelativeLayoutandroid:layout_alignParentBottom="true"と入力します。

また、コンテナを閉じる必要があります。 ;)

0

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> 

そしてcontent_main.xml内での使用このコードは、次のコードを使用しています。

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

あなたはRelativeLayoutを使用することができますが、以下のようのLinearLayoutのinsted:

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