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
<?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
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.
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.
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.
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"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With