android - Putting ImageView on the bottom of the screen -


i trying put imageview on bottom of layout following xml:

        <?xml version="1.0" encoding="utf-8"?>         <linearlayout xmlns:android="http://schemas.android.com/apk/res/android"             xmlns:tools="http://schemas.android.com/tools"             android:layout_width="fill_parent"             android:layout_height="fill_parent"             android:orientation="vertical"             tools:context=".mainactivity" >             <linearlayout                 android:layout_width="fill_parent"                 android:layout_height="fill_parent"                 android:background="#eeeeee"                 android:gravity="center"                 android:orientation="horizontal" >                 <imageview                     android:layout_width="wrap_content"                     android:layout_height="wrap_content"                     android:layout_gravity="bottom"                     android:src="@drawable/photo" />             </linearlayout>         </linearlayout> 

i following instructions found here http://sandipchitale.blogspot.co.uk/2010/05/linearlayout-gravity-and-layoutgravity.html

only difference use imageview instead of button 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"     android:orientation="vertical" >     <linearlayout         android:layout_width="fill_parent"         android:layout_height="fill_parent"         android:gravity="center"         android:orientation="horizontal" >         <button             android:id="@+id/button03"             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:layout_gravity="bottom"             android:text="bottom" >         </button>     </linearlayout> </linearlayout> 

which puts button on expected place:

enter image description here

unfortunately isn't case in xml on top of post. imageview isn't placed on bottom button in reference xml is.

enter image description here

any ideas why happens ?

try using relativelayout instead of linearlayout , use parameter android:layout_alignparentbottom = "true".

edit: try giving layout_height , layout_width wrap_content linearlayout holds imageview.

or might image using has space above , below it.

update:

the problem size of image. larger screen size. suggest programmatically read screen size of device below code:

displaymetrics displaymetrics = new displaymetrics(); getwindowmanager().getdefaultdisplay().getmetrics(displaymetrics); int height = displaymetrics.heightpixels; int width = displaymetrics.widthpixels; 

and set height , width imageview programmatically below:

image_view.getlayoutparams().height = height - 50; image_view.getlayoutparams().width = width - 50; 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -