开发者

Android Layout align bottom

I have following layout in my application:

  <?xml version="1.0" encoding="utf-8"?>
  <ScrollView  
     xmlns:android="http://schemas.android.com/apk/res/android"
     android:id="@+id/ScrollView01"
     android:layout_width="fill_parent"
     android:layout_height="fill_parent"
     android:scrollbars="vertical"
     android:background="@drawable/bbg">
     <LinearLayout
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1">
        <TextView
           android:id="@+id/Title"
           android:text="@string/order_status"
           android:layout_width="fill_parent"
           android:layout_height="wrap_content"
           android:gravity="center_horizontal"
           android:textSize="26sp"
           android:textColor="#000000"
           android:shadowColor="#FFFFFF"
           android:shadowDx="0.5"
           android:shadowDy="0.5"
           android:shadowRadius="1.0"/>
           <LinearLayout
              android:orientation="vertical"
              android:id="@+id/MainStatusWindow"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"
              android:layout_margin="10sp"
              android:background="@drawable/rounded_corners">
              <TextView
                 android:id="@+id/RateInfo"
                 android:text=""
                 android:layout_width="fill_parent"
                 android:layout_height="wrap_content"
                 android:textSize="16sp"
                 android:layout_margin="10开发者_JAVA技巧sp"
                 android:textColor="#5C5C5C"/>
              <ImageView
                 android:src="@drawable/line"
                 android:layout_width="fill_parent"
                 android:layout_height="wrap_content"
                 android:scaleType="fitXY"/>
              <TextView
                 android:id="@+id/OrderStatus"
                 android:text="@string/please_wait"
                 android:layout_width="fill_parent"
                 android:layout_height="wrap_content"
                 android:gravity="center_horizontal"
                 android:textSize="20sp"
                 android:layout_margin="10sp"
                 android:textColor="#222222"/>
              <ImageView
                 android:src="@drawable/line"
                 android:layout_width="fill_parent"
                 android:layout_height="wrap_content"
                 android:scaleType="fitXY"/>
              <TextView
                 android:id="@+id/TimerStatus"
                 android:text="0:00"
                 android:layout_width="fill_parent"
                 android:layout_height="wrap_content"
                 android:gravity="center_horizontal"
                 android:textSize="50sp"
                 android:layout_margin="10sp"
                 android:textColor="#222222"/>
           </LinearLayout>
           <Button android:id="@+id/Cancel"
              android:layout_marginTop="10sp"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:text="@string/cancel_order"
              android:textSize="18sp"
              android:textColor="#111111"
              android:layout_alignParentBottom="true"
              android:background="@drawable/button_red"/>
     </LinearLayout>
  </ScrollView>

I need to last button to be on the bottom of page. Picture bellow shows what I need (On the left what I have, on the right what I need).

Android Layout align bottom

Thank you.


The general layout organization should be:

<LinearLayout orientation="vertical">
    <ScrollView android:layout_weight="1"
         android:width="fill_parent"
         android:height="wrap_content">
        ... linear layout with your TextViews ...
    </ScrollView>
    <Button/>
</LinearLayout>

The layout_weight="1" attribute causes that view to fill the available space in the outer LinearLayout and will push your button to the bottom.

Edit - if you want the buttons to scroll as well, then you should follow Romain Guy's article, using fillViewPort and setting a layout_weight on one of your LinearLayout children.


Have you tried android:fillViewPort= true in ScrollView ?

Check here,

http://www.curious-creature.org/2010/08/15/scrollviews-handy-trick/


You can use put your ScrollView and the button inside a RelativeLayout and set android:layout_alignParentBottom for the button.


This is a common problem but easy to fix:

1) Use a relativeLayout 2) In there, have two Views or Layouts. First one align to the top and have a bottom margin equal to the height of the bottom one. Second one align to the bottom

Done! Hope this helps.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜