2017-07-18 92 views
0

我想放置一個按鈕在我的LinearLayout的結束和製造類似this按鈕放置在LinearLayout中

所以我創建了一個佈局和分配的漸變背景以實現的期待,但我發現很難放置按鈕上的LinearLayout fragment_edit_profile.xml

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@drawable/bg_toolbar_gradient" 
    android:padding="20dp" 
    android:scrollbars="none"> 

    <LinearLayout 
     android:padding="20dp" 
     android:layout_width="match_parent" 
     android:orientation="vertical" 
     android:layout_height="wrap_content" 
     android:gravity="center" 
     android:background="@drawable/bg_edit_profile"> 
     <EditText 
      android:layout_width="match_parent" 
      android:layout_height="50dp" 
      android:background="@color/white" 
      android:padding="10dp" 
      android:layout_margin="5dp" 
      android:hint="First Name" /> 

     <EditText 
      android:layout_width="match_parent" 
      android:layout_height="50dp" 
      android:background="@color/white" 
      android:padding="10dp" 
      android:layout_margin="5dp" 
      android:hint="Last Name" /> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="20dp" 
      android:layout_marginBottom="5dp" 
      android:orientation="vertical"> 
      <!-- Email --> 
      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:textColor="@color/darkGrey" 
       android:text="Email" 
       android:textSize="18sp" 
       android:layout_margin="5dp"/> 

      <EditText 
       android:layout_width="match_parent" 
       android:layout_height="50dp" 
       android:background="@color/white" 
       android:padding="10dp"/> 
     </LinearLayout> 
     <Button 
      android:layout_width="200dp" 
      android:layout_height="50dp" 
      android:textColor="@color/white" 
      android:text="Save Changes" 
      android:background="@drawable/button_dark_filled"/> 
    </LinearLayout> 
</ScrollView> 

的邊界難道你們有什麼想法,我怎麼能做到這一點?我搜索,但沒有發現任何有用的..在此先感謝!

回答

1

這裏是我如何實現它:

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@android:color/white" 
    android:orientation="vertical"> 

    <FrameLayout 
     android:id="@+id/frame_layout" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="0.6"> 

     <LinearLayout 
      android:id="@+id/edit_text_linear_layout" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_marginBottom="25dp" 
      android:orientation="vertical" 
      android:background="@color/colorAccent"> 

      <EditText 
       android:id="@+id/first_name_entry" 
       android:layout_width="match_parent" 
       android:layout_height="50dp" 
       android:layout_margin="5dp" 
       android:hint="First Name" 
       android:padding="10dp" /> 

      <EditText 
       android:id="@+id/last_name_entry" 
       android:layout_width="match_parent" 
       android:layout_height="50dp" 
       android:layout_margin="5dp" 
       android:hint="Last Name" 
       android:padding="10dp" /> 

      <TextView 
       android:id="@+id/email_title" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_margin="5dp" 
       android:text="Email" 
       android:textSize="18sp" /> 

      <EditText 
       android:id="@+id/email_entry" 
       android:layout_width="match_parent" 
       android:layout_height="50dp" 
       android:padding="10dp" /> 
     </LinearLayout> 

    <Button 
     android:id="@+id/save_button" 
     android:layout_width="wrap_content" 
     android:layout_height="50dp" 
     android:layout_gravity="bottom|center_horizontal" 
     android:background="@color/colorPrimary" 
     android:text="Save Changes" 
     android:paddingLeft="10dp" 
     android:paddingRight="10dp" 
     android:textSize="18sp" /> 

    </FrameLayout> 

    <LinearLayout 
     android:id="@+id/bottom_container" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="0.4" 
     android:orientation="vertical" /> 

</LinearLayout> 
+0

我很抱歉,你可以給我做了什麼,你在這裏做解釋,我發現很難嘗試你的代碼 – Anas

+0

當然!由於frame_layout是按鈕和edit_text_linear_layout的父級,它們可以重疊。如果您使用自己的colors.xml中的資源更改背景顏色,可能會更容易一些。 – sav621

1

您需要的FrameLayout或RelativeLayout的在外面的LinearLayout。

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:background="@drawable/bg_toolbar_gradient" 
android:padding="20dp" 
android:scrollbars="none" 
android:fillViewport="true"> 
<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 
    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="@drawable/bg_edit_profile" 
     android:layout_alignBottom="@id/input_form" 
     android:layout_marginBottom="45dp"/> 
    <LinearLayout 
     android:padding="20dp" 
     android:layout_width="match_parent" 
     android:orientation="vertical" 
     android:layout_height="wrap_content" 
     android:gravity="center" 
     android:id="@+id/input_form" 
     > 
     <EditText 
      android:layout_width="match_parent" 
      android:layout_height="50dp" 
      android:background="@color/white" 
      android:padding="10dp" 
      android:layout_margin="5dp" 
      android:hint="First Name" /> 

     <EditText 
      android:layout_width="match_parent" 
      android:layout_height="50dp" 
      android:background="@color/white" 
      android:padding="10dp" 
      android:layout_margin="5dp" 
      android:hint="Last Name" /> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="20dp" 
      android:layout_marginBottom="5dp" 
      android:orientation="vertical"> 
      <!-- Email --> 
      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:textColor="@color/darkGrey" 
       android:text="Email" 
       android:textSize="18sp" 
       android:layout_margin="5dp"/> 

      <EditText 
       android:layout_width="match_parent" 
       android:layout_height="50dp" 
       android:background="@color/white" 
       android:padding="10dp"/> 
     </LinearLayout> 
     <Button 
      android:layout_width="200dp" 
      android:layout_height="50dp" 
      android:textColor="@color/white" 
      android:text="Save Changes" 
      android:layout_alignParentBottom="true" 
      android:layout_centerHorizontal="true" 
      android:layout_below="@+id/input_form" 
      android:background="@drawable/button_dark_filled"/> 
    </LinearLayout> 


</RelativeLayout> 

+0

感謝您的回覆。當我添加更多視圖(使用TextView和EditText的更多linearLayouts)時,我失去了內部背景 – Anas

+0

LinearLayout中添加了視圖,其中id ** input_form **? – Fr099y

+0

是的,我添加了更多的意見,input_form – Anas