2016-05-30 68 views
0

私がこれまでにこのレイアウトを持っている:カードビューの中央下部中央にビューを配置するにはどうすればよいですか?

enter image description here

<android.support.design.widget.CoordinatorLayout 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="150dp"> 

<android.support.v7.widget.CardView 
    android:id="@+id/viewA" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"></android.support.v7.widget.CardView> 

<android.support.design.widget.FloatingActionButton 
    android:id="@+id/fab" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_margin="16dp" 
    android:clickable="true" 
    app:layout_anchor="@id/viewA" 
    app:layout_anchorGravity="bottom|center"/> 

しかしどのように私はコーディネーターのレイアウトの(幅の)真ん中下にボタンを配置して持つことができますこのような結果ですか? :

enter image description here

答えて

1

あなたはCardViewlinearlayoutを使用する必要がありますし、FAB、このような何かの属性app:layout_anchorでそれを使用します。

FAB in middle-bottom of cardview

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:card_view="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context=".vistas.fragments.FragmentDatosTab"> 

    <android.support.v7.widget.CardView 
     android:id="@+id/cv" 
     android:layout_width="350dp" 
     android:layout_height="500dp" 
     android:layout_gravity="center" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior" 
     card_view:cardCornerRadius="6dp" 
     card_view:cardElevation="5dp" 
     card_view:cardPreventCornerOverlap="false" 
     card_view:cardUseCompatPadding="true"> 

     <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      android:id="@+id/linearlayout" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:gravity="center_horizontal" 
      android:orientation="vertical"> 

     </LinearLayout> 

    </android.support.v7.widget.CardView> 

    <android.support.design.widget.FloatingActionButton 
     android:id="@+id/bt_iniciar_sesion" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:clickable="true" 
     android:src="@drawable/ic_arrow_forward_white_24dp" 
     app:backgroundTint="@color/colorPrimary" 
     app:layout_anchor="@id/linearlayout" 
     app:layout_anchorGravity="center_horizontal|bottom" /> 

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

これが結果です

関連する問題