2017-04-04 420 views
0

我有一個水平方向的線性佈局。在水平方向,我有3個部件ImageButtonEdittextFabbuttonAndroid Material Design

如何將Imagebutton對齊到左側,其左側,右側,頂部和底部的填充應該相同?

<?xml version="1.0" encoding="utf-8"?> 
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/activity_main" 
    android:layout_width="match_parent"`enter code here` 
    android:layout_height="match_parent" 

    tools:context="com.example.ashwini.chatscreen.MainActivity"> 

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

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="bottom" 
     android:orientation="horizontal"> 
     <ImageButton 
      android:layout_width="0dp" 
      android:layout_height="50dp" 
      android:layout_gravity="left|center_vertical" 
      android:layout_weight="1" 
      android:background="@drawable/ic_down_arrow" 
      android:id="@id/downButton"/> 
     <EditText 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:paddingLeft="30dp" 
      android:layout_weight="3" 
      > 
      <requestFocus></requestFocus> 
     </EditText> 


     <android.support.design.widget.FloatingActionButton 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_gravity="right|center_vertical" 
      android:src="@drawable/ic_send_message_button" 
      android:layout_weight="0.86"/> 
    </LinearLayout> 

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

無法理解你的需求。你能展示一張照片嗎?你有什麼需要? – Ircover

回答

0

試試這個代碼:

<?xml version="1.0" encoding="utf-8"?> 
<android.support.design.widget.CoordinatorLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/activity_main" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:gravity="center" 
      android:layout_gravity="bottom" 
      android:orientation="horizontal"> 

      <EditText 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_weight="3" /> 

      <ImageButton 
       android:layout_width="0dp" 
       android:layout_height="50dp" 
       android:layout_weight="1" 
       android:padding="16dp" 
       android:background="@drawable/down_arrow"/> 

      <android.support.design.widget.FloatingActionButton 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:src="@drawable/com_facebook_send_button_icon" 
       android:layout_weight="0.86"/> 
     </LinearLayout> 

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

Preview here