Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to achieve alignParentBottom="true" property in LinearLayout

Tags:

android

If i want to set an image to the bottom of any screen then we can use android:layout_alignParentBottom="true" in relative layout. But because of some reason i am bound to use LinearLayout. There are other views (button, image button, listview) in the screen also. I want to place image at the bottom of my screen. Whatever may be the situation user wil be able to see this imageview at the bottom of the screen. How to achieve alignParentBottom="true" property in LinearLayout. See the folowing sample xml. I am using example1.xml but i want look and file that of example2.xml

example1.xml

enter image description here

  <?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <TextView
        android:id="@+id/textview1"
        android:layout_width="fill_parent"
        android:layout_height="40dip"
        android:background="#ffffff"
        android:textColor="#000000"
        android:text="I am sunil" 
        android:gravity="bottom"/>

</LinearLayout>

example2.xml

<

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

    <RelativeLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <TextView
            android:id="@+id/textview1"
            android:layout_width="fill_parent"
            android:layout_height="40dip"
            android:background="#ffffff"
            android:textColor="#000000"
            android:text="I am sunil" 
            android:layout_alignParentBottom="true"/>

    </RelativeLayout>

Thanks

like image 406
Sunil Kumar Sahoo Avatar asked Jul 05 '11 07:07

Sunil Kumar Sahoo


People also ask

Which is better LinearLayout or RelativeLayout?

LinearLayout is less used as compared to RelativeLayout. RelativeLayout is used more in applications. We can use LinearLayout inside RelativeLayout. We can also use RelativeLayout as a Child of LinearLayout.

Which attribute or property is specific for RelativeLayout?

Some of the many layout properties available to views in a RelativeLayout include: android:layout_alignParentTop. If "true" , makes the top edge of this view match the top edge of the parent. android:layout_centerVertical.

How do you align buttons in relative layout?

The 2 buttons are placed below the TextView having id textView. This is done by using the android:layout_below="@+id/textView" attribute in both the Button tags. We have aligned both the buttons from the top margin (of each other), using android:layout_alignTop="@id/button" attribute.


1 Answers

Assuming that you have both a gallery view and a listview, you could add weight to one of them, meaning that it would grow as much as possible. If you give a weight to more than one view, they will share the extra space proportionally.

For instance, add to your gallery and listview android:layout_weight="1"

like image 53
Pedro Loureiro Avatar answered Sep 21 '22 21:09

Pedro Loureiro