2017-07-18 95 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