Prevent images from showing in ImageView

I have a linear layout that contains an image and another linear layout that is the bottom pane on the screen. I am using the bottom panel elsewhere in my project and I don't think this is a problem.

The problem is that the image is viewing the entire screen. The image itself does not, but it does. I can not understand this. As you can see in my xml, I do not use fill_parent for the image, and I tried every possible type of scaleType for the image.

Any suggestions? Also, if that helps, I create Android API 8

Edit: I changed the xml below so that you can use exactly what I wrote. (This is the image I use in the image view: http://i.imgur.com/qN5aT.jpg )

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:background="#FFFFFF" > <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:scaleType="fitStart" android:src="@drawable/quote_sample_img" /> <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="bottom" android:orientation="vertical" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="This is text" /> </LinearLayout> </LinearLayout> 

http://i.imgur.com/m3msH.png (Sorry, not enough reputation to post the actual image)

+8
android android-layout android-imageview imageview
source share
4 answers

Everything seems to work if android is added to the ImageView: layout_weight = "1.0".

(I'm not sure what exactly is happening and in what order in the layout algorithm, so I can’t explain why.)

 <?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" android:background="#FFFFFF" > <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1.0" android:scaleType="fitStart" android:src="@drawable/quote_sample_img" /> <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="bottom" android:orientation="vertical" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="This is text" /> </LinearLayout> </LinearLayout> 
+11
source share

This is wrap_content in the image - the source file is probably too tall.

Use this in your ImageView to resize the image before resetting to a new image size after scaling:

 android:adjustViewBounds="true" 

I would also change the height of the ImageView so that it fills the screen and makes your bar always be down:

 android:layout_height="0dip" // faster than match_parent for weight android:layout_weight="1.0" 
+1
source share

I think the problem may be that the image you used is larger than the screen, so the ImageView has a height set to the height of the available space to best match the image, leaving no room for anything else.

In addition, if you want the bottom panel to always be displayed, it is better to use a RelativeLayout, namely:

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" style="@style/Main" android:orientation="vertical" > <LinearLayout android:id="@+id/bottom_bar" android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="bottom" android:layout_alignParentBottom="true" android:orientation="vertical" > <include layout="@layout/browse_bottom_bar" /> </LinearLayout> <ImageView android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_above="@id/bottom_bar" android:src="@drawable/quote_sample_img" /> </RelativeLayout> 
0
source share

I have a very similar problem posted at https://stackoverflow.com/questions/9765401/imageview-with-adjustviewbounds-seems-to-ignore-following-elements

ImageView doesn't seem to shrink after scaling the image IF you don't specify adjustviewbounds = "true".

But, as you can see from my own message, that is not the complete answer: the image can still push elements below the display or intrude into their space if the image is too large, and I'm trying to fix it.

0
source share

All Articles