开发者

How to align included layout bottom in android?

开发者 https://www.devze.com 2023-03-16 23:34 出处:网络
I have layout included inside another layout , I want this included one aligned bottom when I include it

I have layout included inside another layout , I want this included one aligned bottom when I include it

<开发者_JAVA百科;?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical" android:layout_width="fill_parent"
        android:layout_height="fill_parent">

<Button 
        android:text="Enter Piano course" 
        android:id="@+id/btnEnterCourse" 
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"></Button>

<include 
                layout="@layout/powered_by_bar"></include>
</LinearLayout>

in this code sample I want to align powered_by_bar to the bottom of the interface


In a vertical LinearLayout you cannot align at bottom (or at top) but left or right. In horizontal LinearLayout you can align bottom and top but not left or right.

To do that you have to wrap the inner LinearLayout in a horizontal LinearLayout and set the layout_weight and layout_gravity correctly:

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:orientation="vertical" android:layout_width="fill_parent"
            android:layout_height="fill_parent">

            <Button android:text="Enter Piano course" 
                    android:id="@+id/btnEnterCourse" 
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"></Button>

            <LinearLayout android:layout_weight="1" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="fill_parent" >
                    <LinearLayout android:background="#0000ff" android:layout_gravity="bottom" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="30dip" />
            </LinearLayout>
    </LinearLayout>


Use RelativeLayout,it is more efficient than LinearLayout and it has many attributes to align the items as we want.You can use those RelativeLayout attributes in "include" tag also. from android developer site "Similarly, you can override all the layout parameters. This means that any android:layout_* attribute can be used with the tag." see http://developer.android.com/resources/articles/layout-tricks-reuse.html

0

精彩评论

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