Alright so there's another interesting option on the attributes pane for image views, and that's adjust
view bounds.
So I'm going to make sure that image view's selected over here, and you can see over here we've got adjust view bounds.
Now I'm going to leave that set to false to start with,
and we're going to change it later so that we can see the effect.
But if we want to see what it does, or found out more about what it does, I'm just going to go into Google in a
browser.
We'll do a search for image view dot adjust view bounds. You can see that's the first option there, and then we want to click
on the first option which is the widget image view page on developer dot android dot com. And this is obviously
Google's documentation and it's an excellent place to start.
Now this page is the documentation for the image view widget. So it describes all the methods and properties
you can use with an image view.
And you can actually use control f to search for adjust view bounds on the page, and if I do that myself on the Mac with
command f, adjust view bounds, and you can see in the top right hand corner,
we've got 21 matches there.
Now we set this to true,
if we want the image view to adjust its bounds, to preserve the aspect ratio of its drawable.
Now it's drawable, remember, is the image that it contains.
Now this seems a bit odd.
We've told the image view to scale its drawable, to fit the image view, but now we're also telling the image view to
alter its size to fit the drawable.
Well it's actually a two step process.
The image will be scaled to fit, then the image view will resize itself,
so there's no space around the image on either side.
Now if you're struggling to understand that, it'll make sense once you see it in action.
Now if we have look at this set adjust view bounds, set adjust view bounds, but there are 20 other references
on this page so it's well worth checking out everything
that the documentation has to say about something, rather than just settling on the first thing you
read.
So I'm going to flick on through some of the other references.
I'm not going to spend time reading each one though because the video will go on forever.
But I'll just forward and start looking at some of these matches.
This one here is the one that I particularly want you to see, and it was actually the 12th match.
Now this note here is quite interesting, especially if you're targeting API 17.
So the image view doesn't always grow to fill the available space when you're using adjust view bounds.
That's expected behavior,
and we don't have to spend days working out why. Reading the documentation doesn't just mean glancing at
the first couple of paragraphs.
It's well worth spending the time to read it thoroughly,
if you've gone to the trouble of searching for it in the first place. And it can save you a lot of time
trying to sort out problems, when things don't work as you might expect. Now here you could've wasted
a lot of time, trying to debug something that isn't a bug.
Well arguably it is,
but once a bugs documented of course, it becomes a feature.
So it looks like I should probably set adjust view bounds to true here, but if I go back to Android
Studio now, we would normally do that by clicking on this little try state button, and that lets us choose
from true when it's clicked, when it's ticked rather. So that's true now,
false when isn't.
So that would be false, and whatever the default setting is when it's got a dash through it, which
it was originally set to.
So I'm going to leave it set to the default though, so that we can switch it on later and see what effect it has.
And that's better than just trying to imagine it.
So something that's not obvious though is that the blueprint's showing us how much height our layout row's
taking up on the screen.
Now the solid outline running to the bottom of the layout is indicating that our widgets will display at the full
height of the screen.
Now that's important because the recycler view will be trying to fit as many of these layouts on the
screen as possible, to give a scrollable list.
Now something's causing that,
and as the text in the text view is just the word text view, it's unlikely to be that.
So let's have a look at the image view.
So making sure that you've selected that, and its layout height's set to match underscore parent, which
we set it to, which means it'll be as high as possible.
Now if I change that back to wrap underscore content, it shrinks to a more reasonable size.
The outline though is still filling the screen though, which isn't what we want.
Now if the outline still extends all the way to the bottom of the screen, that indicates that the linear
layout's layout underscore height is set to match underscore parent.
And that can mess up the display when you use it in something like a list view or recycler view.
So in other words what we want to do here is make sure our layout underscore height, select the layout, I want to make sure
the layout underscore height is in fact set to wrap content.
So I'm going to do that, and you can see when I did that the outline shrunk.
And if I go back and click on match underscore parent again, you can see that it expands, so I want to set it back to to wrap
underscore content here.
Now it doesn't always show in the designer, but this is where the blueprint's incredibly useful, because
it always shows things like that.
Now although it wouldn't have been the end of the world if we'd missed it, we'd have to have come back and change
the layout after running the app, to make it look right.
Alright so we're good to go at this point.
So I'm going to go back into text, the text tab, and reformat the code.
Back to design, and I'll finish the video here. In the next one,
we're going to continue to create the other layouts for the app. So I'll see you in the next video.