2014-01-14 118 views
0

我有这样的布局:对齐按钮,屏幕的LinearLayout的BUTTOM

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

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

     <ImageView 
      android:id="@+id/imageView1" 
      android:layout_width="66dp" 
      android:layout_height="64dp" 
      android:layout_marginLeft="10dp" 
      android:layout_marginTop="10dp" 
      android:src="@drawable/office_girl" /> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="10dp" 
      android:orientation="vertical" > 

      <TextView 
       android:id="@+id/greetingTextView" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Hi Boss," 
       android:textStyle="bold" /> 

      <TextView 
       android:id="@+id/dailyStatusTextView" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="What to say if someone call?" /> 
     </LinearLayout> 
    </LinearLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="90dp" 
     android:layout_marginTop="10dp" 
     android:orientation="horizontal" > 
<!--   android:layout_gravity="center" --> 

     <EditText 
      android:id="@+id/suto_sms_text" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_marginTop="3dp" 
      android:hint="Text" 
      android:inputType="textMultiLine" 
      android:lines="3" /> 

    </LinearLayout> 

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

     <TextView 
       android:id="@+id/text_phone_status" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:text="Phone Status" 
       android:layout_marginTop="3dp" 
       android:layout_marginLeft="5dp" 
       android:textSize="20sp" /> 
     <Spinner 
      android:id="@+id/spinner_phone_status" 
      android:layout_width="120dp" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="30dp"/> 

    </LinearLayout> 

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

     <TextView 
       android:id="@+id/text_busy_until" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:text="until" 
       android:layout_marginTop="3dp" 
       android:layout_marginLeft="5dp" 
       android:textSize="20sp" /> 
     <Button 
      android:enabled="true" 
      android:id="@+id/button_set_date_and_time" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="3dp" 
      android:layout_marginLeft="30dp" 
      android:text="@string/set_time" /> 
     <TextView 
       android:enabled="true" 
       android:id="@+id/text_date_and_time" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:layout_marginTop="3dp" 
       android:layout_marginLeft="40dp" 
       android:textSize="12sp" 
       android:textStyle="bold"/> 


    </LinearLayout> 

    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="10dp" 
     android:layout_gravity="center_horizontal" 
     android:orientation="horizontal" > 
     <Button 
      android:id="@+id/button_confirm" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="3dp" 
      android:text="@string/button_confirm" /> 
     <Button 
      android:id="@+id/button_cancel" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="3dp" 
      android:layout_marginLeft="3dp" 
      android:text="@string/button_cancel" /> 



    </LinearLayout> 

</LinearLayout> 

这是输出的一部分:

enter image description here

我的问题是如何使我的确认和取消按钮(XML的最后部分)到屏幕的按钮?

我看到了如何使用相对布局可以完成的示例,但是我的xml非常大,我不想将其更改为相对布局,因为这意味着大量工作。

谢谢。

+0

尝试RelativeLAyout。 –

+1

@amitsingh OP表示他看到了使用'RelativeLayout'的答案,但他不想改变一切。这就是说,@迈克尔A,我认为这是值得的切换到'RelativeLayout',因为我认为这是唯一的方法,你将得到你需要使用不同的屏幕,等等。如果这是你的整个布局,那么它不会很难改变。为每个孩子添加'android:layout_below =“@ idToBeBelow”',并给每个孩子'LinearLayuot'''''。没有更多的它 – codeMagic

+0

我被困在同样的问题,我使用layout_wieght = 0.75顶部和din't指定底部元素的任何东西。它的工作。 – kAnNaN

回答

0

试试这个代码

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

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="0dp" 
    android:layout_weight="0.9" 
    android:orientation="vertical" > 

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

     <ImageView 
      android:id="@+id/imageView1" 
      android:layout_width="66dp" 
      android:layout_height="64dp" 
      android:layout_marginLeft="10dp" 
      android:layout_marginTop="10dp" /> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="10dp" 
      android:orientation="vertical" > 

      <TextView 
       android:id="@+id/greetingTextView" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Hi Boss," 
       android:textStyle="bold" /> 

      <TextView 
       android:id="@+id/dailyStatusTextView" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="What to say if someone call?" /> 
     </LinearLayout> 
    </LinearLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="90dp" 
     android:layout_marginTop="10dp" 
     android:orientation="horizontal" > 

     <!-- android:layout_gravity="center" --> 

     <EditText 
      android:id="@+id/suto_sms_text" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_marginTop="3dp" 
      android:hint="Text" 
      android:inputType="textMultiLine" 
      android:lines="3" /> 
    </LinearLayout> 

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

     <TextView 
      android:id="@+id/text_phone_status" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="5dp" 
      android:layout_marginTop="3dp" 
      android:text="Phone Status" 
      android:textSize="20sp" /> 

     <Spinner 
      android:id="@+id/spinner_phone_status" 
      android:layout_width="120dp" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="30dp" /> 
    </LinearLayout> 

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

     <TextView 
      android:id="@+id/text_busy_until" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="5dp" 
      android:layout_marginTop="3dp" 
      android:text="until" 
      android:textSize="20sp" /> 

     <Button 
      android:id="@+id/button_set_date_and_time" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="30dp" 
      android:layout_marginTop="3dp" 
      android:enabled="true" 
      android:text="set_time" /> 

     <TextView 
      android:id="@+id/text_date_and_time" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="40dp" 
      android:layout_marginTop="3dp" 
      android:enabled="true" 
      android:textSize="12sp" 
      android:textStyle="bold" /> 
    </LinearLayout> 
</LinearLayout> 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_weight="0.025" 
    android:baselineAligned="true" 
    android:gravity="center" 
    android:orientation="horizontal" > 

    <Button 
     android:id="@+id/button_confirm" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="confirm" /> 

    <Button 
     android:id="@+id/button_cancel" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="cancel" /> 
</LinearLayout> 

在这里,您使用很多LinearLayouts的,但我个人建议你尝试relativelayout

0

使用按钮上的android:layout_gravity="bottom"属性及其包含LinearLayout

+0

bottom'gravity'不适用于垂直对齐的'LinearLayout'。 – codeMagic

0

添加

android:layout_weight="1" 
在倒数第二的LinearLayout

android:layout_weight="0" 

在最后的LinearLayout。希望为你工作。

0

这其实非常容易使用的RelativeLayout的,因为你可以非常聪明。例如,它环绕的一切,让你的当前父线性布局将是第一个孩子,年底投用的按钮线性布局在当前父外与参数alignParentBottom

请看到这一点:

<?xml version="1.0" encoding="utf-8"?> 

<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

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

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

     <ImageView 
      android:id="@+id/imageView1" 
      android:layout_width="66dp" 
      android:layout_height="64dp" 
      android:layout_marginLeft="10dp" 
      android:layout_marginTop="10dp" 
      android:src="@drawable/plus" /> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="10dp" 
      android:orientation="vertical" > 

      <TextView 
       android:id="@+id/greetingTextView" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Hi Boss," 
       android:textStyle="bold" /> 

      <TextView 
       android:id="@+id/dailyStatusTextView" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="What to say if someone call?" /> 
     </LinearLayout> 
    </LinearLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="90dp" 
     android:layout_marginTop="10dp" 
     android:orientation="horizontal" > 
     <!--   android:layout_gravity="center" --> 

     <EditText 
      android:id="@+id/suto_sms_text" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_marginTop="3dp" 
      android:hint="Text" 
      android:inputType="textMultiLine" 
      android:lines="3" /> 

    </LinearLayout> 

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

     <TextView 
      android:id="@+id/text_phone_status" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:text="Phone Status" 
      android:layout_marginTop="3dp" 
      android:layout_marginLeft="5dp" 
      android:textSize="20sp" /> 
     <Spinner 
      android:id="@+id/spinner_phone_status" 
      android:layout_width="120dp" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="30dp"/> 

    </LinearLayout> 

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

     <TextView 
      android:id="@+id/text_busy_until" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:text="until" 
      android:layout_marginTop="3dp" 
      android:layout_marginLeft="5dp" 
      android:textSize="20sp" /> 
     <Button 
      android:enabled="true" 
      android:id="@+id/button_set_date_and_time" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="3dp" 
      android:layout_marginLeft="30dp" 
      android:text="set_time" /> 
     <TextView 
      android:enabled="true" 
      android:id="@+id/text_date_and_time" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="3dp" 
      android:layout_marginLeft="40dp" 
      android:textSize="12sp" 
      android:textStyle="bold"/> 


    </LinearLayout> 


    </LinearLayout> 

    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="10dp" 
     android:layout_gravity="center_horizontal" 
     android:layout_alignParentBottom="true" 
     android:layout_centerHorizontal="true" 
     android:orientation="horizontal" > 
     <Button 
      android:id="@+id/button_confirm" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="3dp" 
      android:text="confirm" /> 
     <Button 
      android:id="@+id/button_cancel" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="3dp" 
      android:layout_marginLeft="3dp" 
      android:text="cancel" /> 

    </LinearLayout> 

</RelativeLayout>