android - Why do I get white space on top and on the bottom of my ImageView in my RelativeLayout? -


i using relativelayout overlay images. on screen sizes far have tested (from 2.7 10.1 inch) white space on top of image. in ide see relativelayout causing space on top , on bottom of image.

why that? have set height attributes wrap_content , added adjustviewbounds attribute.

note: should know image lot bigger in size, meaning there sort of scaling.

thanks tips!

here code:

<?xml version="1.0" encoding="utf-8"?> <scrollview xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="fill_parent"     android:layout_height="wrap_content"     android:background="#ffffff"     android:orientation="vertical" >  <linearlayout      android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_gravity="center_horizontal"     android:orientation="vertical"      android:focusable="true" android:focusableintouchmode="true">  <textview     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_gravity="center_horizontal"     android:text="@string/bgf"     android:textcolor="#000000"     android:textsize="25sp" />  <relativelayout     android:layout_width="match_parent"     android:layout_height="wrap_content" >      <imageview          android:layout_width="wrap_content"         android:layout_height="wrap_content"          android:adjustviewbounds="true"         android:paddingright="5dp"         android:paddingleft="5dp"         android:paddingbottom="5dp"         android:layout_gravity="center_horizontal"         android:layout_centervertical="true"         android:layout_centerhorizontal="true"         android:src="@drawable/cde"         android:contentdescription="@string/cde" />      <imageview         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:adjustviewbounds="true"         android:layout_gravity="center_horizontal"         android:layout_centervertical="true"     android:layout_centerhorizontal="true"         android:src="@drawable/fgh"         android:contentdescription="@string/abc" />  </relativelayout>   </linearlayout> </scrollview> 

this occuring image scaled down fit area available without losing image's aspect ratio. getting white space because image first occupied available width , according aspect ratio of original image height of brought down.

to clearer understanding, suggest following :

  • set background color of relative layout color

now can understand space between imageview , relativelayout.

once have checked on device, following change , try again

  • set attribute scaletype = "fitxy" in imageview.

this make image scale , occupy complete area available imageview. (the aspect ratio of original image lost in case). come know amount of area imageview occupied.

i suppose once can conclude :

  1. in first run if had set background of relativelayout black, won't visible since imageview occupies entire area without leaving gap.

  2. in second run image cover entire height , width, although aspect ratio lost. hence ascertains imageview cover width , height , no space left, image's aspect ratio ie problem

in case arrive @ different result altogether please inform, can work out

edit :

please remove paddings have given imageview too


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

c++ - End of file on pipe magic during open -