I have a large Png image file that I would like to display and scroll around it as I can do in a WebView. When I load my activity with the image file into an ImageView the image is displayed in the screen but is too small to read. I guess the Zoom controls will help once the image it is at it's normal size. I have tried using the image in a WebView but I don't want the Url displayed.
I've done something similar with a TableLayout. I wrapped it in a ScrollView nested in a HorizontalScrollView and the user is able to scroll around in all directions when my TableLayout takes up more space than what will fit on the screen. I imagine this would work with an ImageView as well. Something like this:
<HorizontalScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</ScrollView>
</HorizontalScrollView>
Create your own Custom Scrollable Image View. I have used this in a game, it works, and you can scroll in x, y directions.
I posted one solution for the same question here: Images in ScrollView in android
You said you tried a WebView but you don't want the URL displayed? Do you mean that you see an address bar at the top? If so, please see the answer to this question.
Related
I'm currently trying to make a simple tic-tac-toe game, consisting of ImageViews on top of the board (also an ImageView). However, when I run the app and click on a tile, the picture appears out of place, even though it seems I had lined up the ImageViews correctly.
What I did was I set each original tile to a blank square, and then when the user clicks on a tile, it would change to either "X" or "O," depending on whose turn it was.
I'm pretty sure the problem has to do with dpi scaling on different devices, but I'm not quite sure how to fix it. Any help would be greatly appreciated!
I've included an image of my problem below:
Instead of using an image to display the grid, I would suggest to use XML views.
Horizontal line:
<View
android:layout_width="match_parent"
android:layout_height="5dp"
android:background="#android:color/black"/>
Vertical Line:
<View
android:layout_width="5dp"
android:layout_height="match_parent"
android:background="#android:color/black"/>
And constraint them between the images.
As one can see in the above image there is a lot of white space around the small image in this ImageView layout. How do I remove the white space and make the image view the same size as the actual image it is displaying? If I make the ImageView smaller, it makes the view smaller but still has white space around the image itself. How do I remove it?
Thanks.
add this XML Attribute to the image view declaration:
adjustViewBounds="true"
For example, your ImageView XML would look like this:
<ImageView
android:adjustViewBounds="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
You simply need to do
android:layout_width="wrap_content"
android:layout_height="wrap_content"
in image view.
In addition to that, u can do below things for good practices
you can use ImageView.ScaleType(FIT_XY) but this will change ration of your image and x,y axis expands independently fill your image view
u need to add android:scaleType="fitXY" in xml file image view for it.
you can use ImageView.ScaleType(FIT_CENTER) it will keep ration and expan x,y until one fill your image view
u need to add android:scaleType="fitCenter" in xml file image view for it.
you can find all of the options by navigating this https://developer.android.com/reference/android/widget/ImageView.ScaleType
I've researched some fixes and none of them worked. What did work was changing from a mipmap to a drawable image. I'm getting other errors, but at least the original problem has been fixed.
I have a layout:
<RelativeLayout
android:id="#+id/wordToFindLayout"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:orientation="horizontal">
</RelativeLayout>
On which I am programmatically adding images (images of letters), and I would like these images to go to the next line when they reach the right part of the screen (kind of carriage return). I initially don't know how many images will be displayed.
At the moment I just don't see the images exceeding the screen width and I didn't find a way to programmatically know when they reach the right side of the screen.
What would be the best way to do that?
I suggest you to use the GridView with the property android:numColumns="X" where X is the number of images per row.
See http://developer.android.com/guide/topics/ui/layout/gridview.html
You can use this library to go to next line:https://github.com/blazsolar/FlowLayout
So I'm trying to put an image inside a scrollview and have the image stretch to fit different sized screens. It'll stretch horizontally, but vertically it always comes out messed up.
I've read so many pages of people with similar problems, but their solutions never work for me. I've tried every different combination possible using different scaleType,layout_width and layout_height, along with trying changing other things around. The closest I've gotten to getting it to work is shown in the code below, using scaleType="centerCrop". It's the only one that stretches the image vertically in ratio, but it cuts off a big chunk of the image from the top and bottom, it'll scroll up and down the image, but only the middle part shows.
The image is a 480x5500 jpeg, if that matters. Originally before I started messing with all that, the app worked just fine on my phone, but then later I realized the image was crunched when I tried it on a tablet. There's gotta be a way to do this in the xml right? I really don't want to have to do things with the image in the java code part. Also I'm hoping to be able to do this using just one image, I don't want to have use a different image for different screen sizes. Please help, thanks.
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="centerCrop"
android:src="#drawable/paper" />
</ScrollView>
may be this help you,
make both height and width wrap_content of ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
and no need ScrollView here.
Try using custom ImageView like AspectRatioImageView mentioned here:
https://stackoverflow.com/a/4688335/944070
the next sample is more than what you ask for :
http://www.androidviews.net/2012/11/photoview/
https://github.com/chrisbanes/PhotoView/tree/master/sample
https://play.google.com/store/apps/details?id=uk.co.senab.p
hotoview.sample
it fits the image to the screen , plus it allows to zoom in/out using pinching gestures.
So I created a simple little app that contains rather tall images inside an ImageSwitcher and due to the height of the images, I've wrapped the ImageSwitcher inside a ScrollView (so the entire image is eventually visible). The interesting thing is that the Image doesnt start at the top of the ScrollView but rather the bottom. The scrolling all works correctly, but I was just curious as to why the top of the image is almost at the bottom of the device screen.
Does anyone know what is causing this behavior?
My images are large drawables (800x600) that are obviously being scaled down in order to fit in the device window, but that still doesn't explain why there is such a large amount of empty space above the image.
I would prefer to just scroll the ImageSwitcher itself but that hasn't worked thus far.
Here is my layout:
<ScrollView android:id="#+id/scroll"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageSwitcher android:id="#+id/switcher"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#FFFFFF"/>
</ScrollView>
My suspicion is that the images are being displayed due to the resolution of the original image. I set ImageView.setScaleType(ScaleType.FIT_START); and this appears to have fixed the problem.
Try to call ImageView.setAdjustViewBounds(true) in addition to setScaleType. If you still have problems with your ImageView (inside ImageSwitcher) taking more space than needed, try to peek at the ImageView with the hierarchyviewer in the SDK tools.