2017-07-18 1 views
1

Je veux placer le bouton d'action flottant entre deux editTexts dans un: comme celui-ci Vignettes cardwithedittextComment aligner FAB entre deux EditTexts

J'ai essayé ce qui suit, mais il ne fonctionne pas.

Comment est-ce que je peux faire ceci? Toute aide serait appréciée.

<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:card_view="http://schemas.android.com/apk/res-auto" 
    xmlns:app="http://schemas.android.com/tools" 
    android:id="@+id/card_view" 
    android:layout_width="match_parent" 
    card_view:cardCornerRadius="25dp" 
    android:layout_height="wrap_content" 
    android:layout_margin="8dp"> 

    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" 

     > 
     <LinearLayout 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:orientation="horizontal" 
      > 
      <EditText 
       android:id="@+id/etOrigin" 
       android:layout_width="204dp" 
       android:layout_height="wrap_content" 
       android:hint="Enter origin address" /> 

     </LinearLayout> 
     <android.support.design.widget.FloatingActionButton 
      android:id="@+id/btnFindPath" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="left" 
      android:layout_marginBottom="16dp" 
      android:layout_marginRight="16dp" 
      android:onClick="fabClick" 
      android:src="@mipmap/ic_add_white_24dp" 
      app:fabSize="normal" 
      app:layout_anchor="@id/fab_coordinator_layout" 
      app:layout_anchorGravity="left|end" /> 


     <LinearLayout 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:orientation="horizontal" 
      > 
      <EditText 
       android:id="@+id/etDestination" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:hint="Enter destination address" /> 

     </LinearLayout> 

     <LinearLayout 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:orientation="horizontal" 
      > 


     </LinearLayout> 


    </LinearLayout> 
</android.support.v7.widget.CardView> 
+0

utilisation de disposition relative ou la mise en page contrainte – Pavan

Répondre

0

Vous pouvez faire this-

<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:card_view="http://schemas.android.com/apk/res-auto" 
    xmlns:app="http://schemas.android.com/tools" 
    android:id="@+id/card_view" 
    android:layout_width="match_parent" 
    card_view:cardCornerRadius="25dp" 
    android:layout_height="wrap_content" 
    android:layout_margin="8dp"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" 
     android:gravity="center"> 
     <LinearLayout 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:orientation="vertical"> 
      <EditText 
       android:id="@+id/etOrigin" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:hint="Enter origin address" /> 
      <EditText 
       android:id="@+id/etDestination" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:hint="Enter destination address" /> 
     </LinearLayout> 

     <android.support.design.widget.FloatingActionButton 
      android:id="@+id/btnFindPath" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="10dp" 
      android:onClick="fabClick" 
      android:src="@drawable/ic_add" 
      app:fabSize="normal" 
      android:layout_gravity="center_vertical" 
      app:layout_anchor="@id/fab_coordinator_layout" /> 

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

J'ai changé le rembourrage et la marge, réglez selon vos besoins.

0

Utilisez RelativeLayout comme ci-dessous:

<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:card_view="http://schemas.android.com/apk/res-auto" 
android:id="@+id/card_view" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:layout_margin="8dp" 
card_view:cardCornerRadius="5dp"> 

<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 

    <LinearLayout 
     android:id="@+id/inputHolder" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_toLeftOf="@+id/fabHolder" 
     android:layout_toStartOf="@+id/fabHolder" 
     android:orientation="vertical"> 

     <EditText 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" /> 

     <EditText 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" /> 

    </LinearLayout> 

    <RelativeLayout 
     android:id="@+id/fabHolder" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignBottom="@+id/inputHolder" 
     android:layout_alignParentEnd="true" 
     android:layout_alignParentRight="true" 
     android:layout_alignTop="@+id/inputHolder"> 

     <android.support.design.widget.FloatingActionButton 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_centerVertical="true" 
      android:src="@android:drawable/ic_menu_send" /> 
    </RelativeLayout> 

</RelativeLayout> 

+0

Vous devez éviter d'utiliser la mise en page relative lorsque cela est possible, et encore moins imbriqués Layouts relatifs. Voir ceci pour l'explication - https://stackoverflow.com/a/17496262/8039601 –

+0

Oui, mais c'est facile pour les débutants. –

+0

Mais dans ce cas, une disposition linéaire imbriquée est plus simple qu'une disposition relative imbriquée. Vois ma réponse. –

0

essayer cela en utilisant la disposition linéaire

<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/tools" 
    xmlns:card_view="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/card_view" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_margin="8dp" 
    card_view:cardCornerRadius="25dp"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal"> 

     <LinearLayout 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:orientation="vertical"> 

      <EditText 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:hint="Your hint" /> 

      <EditText 
       android:id="@+id/etDestination" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:hint="Your hint" /> 
     </LinearLayout> 

     <android.support.design.widget.FloatingActionButton 
      android:id="@+id/btnFindPath" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:onClick="fabClick" 
      android:src="@drawable/ic_down" 
      app:fabSize="normal" 
      android:layout_gravity="center" 
      app:layout_anchor="@id/fab_coordinator_layout" /> 

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