1
00:00:05,600 --> 00:00:10,430
Alright so there's another interesting option on the attributes pane for image views, and that's adjust

2
00:00:10,490 --> 00:00:11,330
view bounds.

3
00:00:11,330 --> 00:00:16,970
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.

4
00:00:16,990 --> 00:00:19,470
Now I'm going to leave that set to false to start with,

5
00:00:19,490 --> 00:00:22,220
and we're going to change it later so that we can see the effect.

6
00:00:22,760 --> 00:00:29,930
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

7
00:00:29,960 --> 00:00:30,720
browser.

8
00:00:33,120 --> 00:00:41,010
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

9
00:00:41,010 --> 00:00:49,080
on the first option which is the widget image view page on developer dot android dot com. And this is obviously

10
00:00:49,080 --> 00:00:52,410
Google's documentation and it's an excellent place to start.

11
00:00:52,450 --> 00:00:58,230
Now this page is the documentation for the image view widget. So it describes all the methods and properties

12
00:00:58,530 --> 00:01:00,160
you can use with an image view.

13
00:01:00,480 --> 00:01:06,740
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

14
00:01:07,020 --> 00:01:14,330
command f, adjust view bounds, and you can see in the top right hand corner,

15
00:01:14,340 --> 00:01:16,120
we've got 21 matches there.

16
00:01:16,500 --> 00:01:18,010
Now we set this to true,

17
00:01:18,090 --> 00:01:24,070
if we want the image view to adjust its bounds, to preserve the aspect ratio of its drawable.

18
00:01:24,060 --> 00:01:28,040
Now it's drawable, remember, is the image that it contains.

19
00:01:28,070 --> 00:01:29,530
Now this seems a bit odd.

20
00:01:29,580 --> 00:01:35,940
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

21
00:01:36,000 --> 00:01:38,510
alter its size to fit the drawable.

22
00:01:38,570 --> 00:01:40,420
Well it's actually a two step process.

23
00:01:40,470 --> 00:01:45,500
The image will be scaled to fit, then the image view will resize itself,

24
00:01:45,600 --> 00:01:49,280
so there's no space around the image on either side.

25
00:01:49,290 --> 00:01:53,380
Now if you're struggling to understand that, it'll make sense once you see it in action.

26
00:01:53,540 --> 00:02:01,860
Now if we have look at this set adjust view bounds, set adjust view bounds, but there are 20 other references

27
00:02:01,860 --> 00:02:04,390
on this page so it's well worth checking out everything

28
00:02:04,680 --> 00:02:08,900
that the documentation has to say about something, rather than just settling on the first thing you

29
00:02:08,910 --> 00:02:09,410
read.

30
00:02:09,600 --> 00:02:11,910
So I'm going to flick on through some of the other references.

31
00:02:12,060 --> 00:02:15,490
I'm not going to spend time reading each one though because the video will go on forever.

32
00:02:15,960 --> 00:02:18,720
But I'll just forward and start looking at some of these matches.

33
00:02:23,720 --> 00:02:28,500
This one here is the one that I particularly want you to see, and it was actually the 12th match.

34
00:02:28,570 --> 00:02:34,340
Now this note here is quite interesting, especially if you're targeting API 17.

35
00:02:34,340 --> 00:02:40,590
So the image view doesn't always grow to fill the available space when you're using adjust view bounds.

36
00:02:40,730 --> 00:02:42,330
That's expected behavior,

37
00:02:42,370 --> 00:02:47,480
and we don't have to spend days working out why. Reading the documentation doesn't just mean glancing at

38
00:02:47,480 --> 00:02:49,090
the first couple of paragraphs.

39
00:02:49,160 --> 00:02:52,130
It's well worth spending the time to read it thoroughly,

40
00:02:52,130 --> 00:02:56,780
if you've gone to the trouble of searching for it in the first place. And it can save you a lot of time

41
00:02:56,810 --> 00:03:02,090
trying to sort out problems, when things don't work as you might expect. Now here you could've wasted

42
00:03:02,090 --> 00:03:05,520
a lot of time, trying to debug something that isn't a bug.

43
00:03:05,720 --> 00:03:07,050
Well arguably it is,

44
00:03:07,190 --> 00:03:10,470
but once a bugs documented of course, it becomes a feature.

45
00:03:10,550 --> 00:03:16,040
So it looks like I should probably set adjust view bounds to true here, but if I go back to Android

46
00:03:16,040 --> 00:03:22,520
Studio now, we would normally do that by clicking on this little try state button, and that lets us choose

47
00:03:22,520 --> 00:03:27,320
from true when it's clicked, when it's ticked rather. So that's true now,

48
00:03:27,550 --> 00:03:29,130
false when isn't.

49
00:03:29,130 --> 00:03:33,720
So that would be false, and whatever the default setting is when it's got a dash through it, which

50
00:03:33,720 --> 00:03:35,160
it was originally set to.

51
00:03:35,610 --> 00:03:41,550
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.

52
00:03:41,670 --> 00:03:43,750
And that's better than just trying to imagine it.

53
00:03:43,770 --> 00:03:48,600
So something that's not obvious though is that the blueprint's showing us how much height our layout row's

54
00:03:48,630 --> 00:03:50,040
taking up on the screen.

55
00:03:50,340 --> 00:03:55,080
Now the solid outline running to the bottom of the layout is indicating that our widgets will display at the full

56
00:03:55,080 --> 00:03:56,800
height of the screen.

57
00:03:56,820 --> 00:04:01,890
Now that's important because the recycler view will be trying to fit as many of these layouts on the

58
00:04:01,890 --> 00:04:05,000
screen as possible, to give a scrollable list.

59
00:04:05,100 --> 00:04:06,720
Now something's causing that,

60
00:04:06,720 --> 00:04:11,270
and as the text in the text view is just the word text view, it's unlikely to be that.

61
00:04:11,280 --> 00:04:12,890
So let's have a look at the image view.

62
00:04:13,170 --> 00:04:18,360
So making sure that you've selected that, and its layout height's set to match underscore parent, which

63
00:04:18,360 --> 00:04:22,380
we set it to, which means it'll be as high as possible.

64
00:04:22,400 --> 00:04:28,830
Now if I change that back to wrap underscore content, it shrinks to a more reasonable size.

65
00:04:28,930 --> 00:04:32,870
The outline though is still filling the screen though, which isn't what we want.

66
00:04:33,050 --> 00:04:37,980
Now if the outline still extends all the way to the bottom of the screen, that indicates that the linear

67
00:04:37,980 --> 00:04:41,620
layout's layout underscore height is set to match underscore parent.

68
00:04:41,910 --> 00:04:46,720
And that can mess up the display when you use it in something like a list view or recycler view.

69
00:04:46,770 --> 00:04:53,550
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

70
00:04:53,550 --> 00:04:56,150
the layout underscore height is in fact set to wrap content.

71
00:04:56,170 --> 00:05:02,010
So I'm going to do that, and you can see when I did that the outline shrunk.

72
00:05:02,140 --> 00:05:07,800
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

73
00:05:07,790 --> 00:05:09,320
underscore content here.

74
00:05:09,500 --> 00:05:15,320
Now it doesn't always show in the designer, but this is where the blueprint's incredibly useful, because

75
00:05:15,320 --> 00:05:17,300
it always shows things like that.

76
00:05:17,330 --> 00:05:21,470
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

77
00:05:21,470 --> 00:05:24,710
the layout after running the app, to make it look right.

78
00:05:25,100 --> 00:05:26,510
Alright so we're good to go at this point.

79
00:05:26,510 --> 00:05:31,910
So I'm going to go back into text, the text tab, and reformat the code.

80
00:05:34,580 --> 00:05:38,150
Back to design, and I'll finish the video here. In the next one,

81
00:05:38,160 --> 00:05:42,850
we're going to continue to create the other layouts for the app. So I'll see you in the next video.

