Skip to content

Commit c4f7de1

Browse files
drewhamiltonymarian
authored andcommitted
[ShapeableImageView] Support contentPadding
Resolves #1871 GIT_ORIGIN_REV_ID=42b91686512ed77d38f5a70a26cc52157ff4184b Co-authored-by: ymarian <[email protected]> PiperOrigin-RevId: 342906676
1 parent a99966a commit c4f7de1

File tree

6 files changed

+490
-74
lines changed

6 files changed

+490
-74
lines changed

catalog/java/io/material/catalog/imageview/ShapeableImageViewMainDemoFragment.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public View onCreateDemoView(
4545
layoutInflater.inflate(R.layout.catalog_imageview, viewGroup, false /* attachToRoot */);
4646
MaterialButtonToggleGroup toggleGroup = view.findViewById(R.id.togglegroup);
4747
ShapeableImageView imageView = view.findViewById(R.id.image_view);
48+
ShapeableImageView iconView = view.findViewById(R.id.icon_view);
4849

4950
SparseArray<ShapeAppearanceModel> shapes = new SparseArray<>();
5051
shapes.put(
@@ -66,10 +67,14 @@ public View onCreateDemoView(
6667
return;
6768
}
6869

70+
ShapeAppearanceModel shape = shapes.get(checkedId);
71+
6972
// Randomly makes dog wink.
7073
imageView.setImageResource(
7174
random.nextBoolean() ? R.drawable.dog_image : R.drawable.dog_image_wink);
72-
imageView.setShapeAppearanceModel(shapes.get(checkedId));
75+
imageView.setShapeAppearanceModel(shape);
76+
77+
iconView.setShapeAppearanceModel(shape);
7378
});
7479

7580
return view;
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
~ Copyright (C) 2020 The Android Open Source Project
4+
~
5+
~ Licensed under the Apache License, Version 2.0 (the "License");
6+
~ you may not use this file except in compliance with the License.
7+
~ You may obtain a copy of the License at
8+
~
9+
~ http://www.apache.org/licenses/LICENSE-2.0
10+
~
11+
~ Unless required by applicable law or agreed to in writing, software
12+
~ distributed under the License is distributed on an "AS IS" BASIS,
13+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
~ See the License for the specific language governing permissions and
15+
~ limitations under the License.
16+
-->
17+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
18+
xmlns:tools="http://schemas.android.com/tools"
19+
android:width="24dp"
20+
android:height="24dp"
21+
android:viewportWidth="24"
22+
android:viewportHeight="24"
23+
android:tint="?attr/colorControlNormal"
24+
tools:ignore="newApi">
25+
<path
26+
android:fillColor="@android:color/white"
27+
android:pathData="M4.5,9.5m-2.5,0a2.5,2.5 0,1 1,5 0a2.5,2.5 0,1 1,-5 0"/>
28+
<path
29+
android:fillColor="@android:color/white"
30+
android:pathData="M9,5.5m-2.5,0a2.5,2.5 0,1 1,5 0a2.5,2.5 0,1 1,-5 0"/>
31+
<path
32+
android:fillColor="@android:color/white"
33+
android:pathData="M15,5.5m-2.5,0a2.5,2.5 0,1 1,5 0a2.5,2.5 0,1 1,-5 0"/>
34+
<path
35+
android:fillColor="@android:color/white"
36+
android:pathData="M19.5,9.5m-2.5,0a2.5,2.5 0,1 1,5 0a2.5,2.5 0,1 1,-5 0"/>
37+
<path
38+
android:fillColor="@android:color/white"
39+
android:pathData="M17.34,14.86c-0.87,-1.02 -1.6,-1.89 -2.48,-2.91 -0.46,-0.54 -1.05,-1.08 -1.75,-1.32 -0.11,-0.04 -0.22,-0.07 -0.33,-0.09 -0.25,-0.04 -0.52,-0.04 -0.78,-0.04s-0.53,0 -0.79,0.05c-0.11,0.02 -0.22,0.05 -0.33,0.09 -0.7,0.24 -1.28,0.78 -1.75,1.32 -0.87,1.02 -1.6,1.89 -2.48,2.91 -1.31,1.31 -2.92,2.76 -2.62,4.79 0.29,1.02 1.02,2.03 2.33,2.32 0.73,0.15 3.06,-0.44 5.54,-0.44h0.18c2.48,0 4.81,0.58 5.54,0.44 1.31,-0.29 2.04,-1.31 2.33,-2.32 0.31,-2.04 -1.3,-3.49 -2.61,-4.8z"/>
40+
</vector>

catalog/java/io/material/catalog/imageview/res/layout/catalog_imageview.xml

Lines changed: 93 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -15,96 +15,116 @@
1515
~ See the License for the specific language governing permissions and
1616
~ limitations under the License.
1717
-->
18-
19-
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
18+
<ScrollView
19+
xmlns:android="http://schemas.android.com/apk/res/android"
2020
xmlns:app="http://schemas.android.com/apk/res-auto"
2121
xmlns:tools="http://schemas.android.com/tools"
22-
android:id="@+id/main_viewGroup"
2322
android:layout_width="match_parent"
24-
android:layout_height="wrap_content"
25-
android:padding="@dimen/cat_imageview_padding"
26-
android:orientation="vertical">
23+
android:layout_height="match_parent">
2724

28-
<com.google.android.material.button.MaterialButtonToggleGroup
29-
android:id="@+id/togglegroup"
30-
android:layout_width="wrap_content"
25+
<LinearLayout
26+
android:id="@+id/main_viewGroup"
27+
android:layout_width="match_parent"
3128
android:layout_height="wrap_content"
32-
android:layout_gravity="center"
33-
app:checkedButton="@id/button_square"
34-
app:selectionRequired="true"
35-
app:singleSelection="true">
36-
<Button
37-
android:id="@+id/button_square"
38-
style="?attr/materialButtonOutlinedStyle"
39-
android:layout_width="wrap_content"
40-
android:layout_height="wrap_content"
41-
android:text="@string/cat_imageview_square" />
29+
android:padding="@dimen/cat_imageview_padding"
30+
android:orientation="vertical">
4231

43-
<Button
44-
android:id="@+id/button_diamond"
45-
style="?attr/materialButtonOutlinedStyle"
46-
android:layout_width="wrap_content"
47-
android:layout_height="wrap_content"
48-
android:text="@string/cat_imageview_diamond" />
49-
<Button
50-
android:id="@+id/button_circle"
51-
style="?attr/materialButtonOutlinedStyle"
32+
<com.google.android.material.button.MaterialButtonToggleGroup
33+
android:id="@+id/togglegroup"
5234
android:layout_width="wrap_content"
5335
android:layout_height="wrap_content"
54-
android:text="@string/cat_imageview_circle" />
36+
android:layout_gravity="center"
37+
app:checkedButton="@id/button_square"
38+
app:selectionRequired="true"
39+
app:singleSelection="true">
40+
<Button
41+
android:id="@+id/button_square"
42+
style="?attr/materialButtonOutlinedStyle"
43+
android:layout_width="wrap_content"
44+
android:layout_height="wrap_content"
45+
android:text="@string/cat_imageview_square" />
5546

56-
</com.google.android.material.button.MaterialButtonToggleGroup>
57-
58-
<com.google.android.material.imageview.ShapeableImageView
59-
android:id="@+id/image_view"
60-
android:layout_margin="10dp"
61-
android:layout_gravity="center"
62-
android:layout_width="match_parent"
63-
android:layout_height="wrap_content"
64-
android:scaleType="fitXY"
65-
android:adjustViewBounds="true"
66-
app:strokeColor="?attr/colorSecondary"
67-
app:shapeAppearance="?attr/shapeAppearanceMediumComponent"
68-
app:strokeWidth="1dp"
69-
android:elevation="5dp"
70-
android:padding="8dp"
71-
app:srcCompat="@drawable/dog_image" />
47+
<Button
48+
android:id="@+id/button_diamond"
49+
style="?attr/materialButtonOutlinedStyle"
50+
android:layout_width="wrap_content"
51+
android:layout_height="wrap_content"
52+
android:text="@string/cat_imageview_diamond" />
53+
<Button
54+
android:id="@+id/button_circle"
55+
style="?attr/materialButtonOutlinedStyle"
56+
android:layout_width="wrap_content"
57+
android:layout_height="wrap_content"
58+
android:text="@string/cat_imageview_circle" />
7259

73-
74-
<LinearLayout
75-
android:layout_width="match_parent"
76-
android:layout_height="wrap_content"
77-
android:layout_margin="10dp"
78-
android:layoutDirection="ltr"
79-
android:orientation="horizontal"
80-
tools:ignore="UnusedAttribute">
60+
</com.google.android.material.button.MaterialButtonToggleGroup>
8161

8262
<com.google.android.material.imageview.ShapeableImageView
83-
android:id="@+id/image_view_jpeg"
84-
android:layout_width="wrap_content"
63+
android:id="@+id/image_view"
64+
android:layout_margin="10dp"
65+
android:layout_gravity="center"
66+
android:layout_width="match_parent"
8567
android:layout_height="wrap_content"
86-
android:adjustViewBounds="true"
8768
android:scaleType="fitXY"
88-
android:elevation="5dp"
89-
app:shapeAppearance="@style/ShapeAppearanceImageLeft"
90-
app:srcCompat="@drawable/cat_image"
69+
android:adjustViewBounds="true"
9170
app:strokeColor="?attr/colorSecondary"
92-
app:strokeWidth="1dp" />
71+
app:shapeAppearance="?attr/shapeAppearanceMediumComponent"
72+
app:strokeWidth="1dp"
73+
android:elevation="5dp"
74+
android:padding="8dp"
75+
app:srcCompat="@drawable/dog_image" />
76+
77+
78+
<LinearLayout
79+
android:layout_width="match_parent"
80+
android:layout_height="wrap_content"
81+
android:layout_margin="10dp"
82+
android:layoutDirection="ltr"
83+
android:orientation="horizontal"
84+
tools:ignore="UnusedAttribute">
85+
86+
<com.google.android.material.imageview.ShapeableImageView
87+
android:id="@+id/image_view_jpeg"
88+
android:layout_width="wrap_content"
89+
android:layout_height="wrap_content"
90+
android:adjustViewBounds="true"
91+
android:scaleType="fitXY"
92+
android:elevation="5dp"
93+
app:shapeAppearance="@style/ShapeAppearanceImageLeft"
94+
app:srcCompat="@drawable/cat_image"
95+
app:strokeColor="?attr/colorSecondary"
96+
app:strokeWidth="1dp" />
97+
98+
<com.google.android.material.imageview.ShapeableImageView
99+
android:id="@+id/image_view_gif"
100+
tools:ignore="InefficientWeight"
101+
android:layout_width="wrap_content"
102+
android:layout_height="match_parent"
103+
android:layout_weight="1"
104+
android:adjustViewBounds="true"
105+
android:scaleType="fitXY"
106+
android:elevation="5dp"
107+
app:shapeAppearance="@style/ShapeAppearanceImageRight"
108+
app:srcCompat="@drawable/cateyes_image"
109+
app:strokeColor="?attr/colorSecondary"
110+
app:strokeWidth="1dp" />
111+
112+
</LinearLayout>
93113

94114
<com.google.android.material.imageview.ShapeableImageView
95-
android:id="@+id/image_view_gif"
96-
tools:ignore="InefficientWeight"
97-
android:layout_width="wrap_content"
98-
android:layout_height="match_parent"
99-
android:layout_weight="1"
100-
android:adjustViewBounds="true"
101-
android:scaleType="fitXY"
102-
android:elevation="5dp"
103-
app:shapeAppearance="@style/ShapeAppearanceImageRight"
104-
app:srcCompat="@drawable/cateyes_image"
105-
app:strokeColor="?attr/colorSecondary"
106-
app:strokeWidth="1dp" />
115+
android:id="@+id/icon_view"
116+
android:layout_margin="10dp"
117+
android:layout_gravity="center"
118+
android:layout_width="40dp"
119+
android:layout_height="40dp"
120+
android:background="?colorSecondary"
121+
android:elevation="2dp"
122+
app:contentPadding="8dp"
123+
app:shapeAppearance="?shapeAppearanceSmallComponent"
124+
app:srcCompat="@drawable/ic_pets_24dp"
125+
app:tint="?colorOnSecondary"
126+
tools:ignore="UnusedAttribute" />
107127

108128
</LinearLayout>
109129

110-
</LinearLayout>
130+
</ScrollView>

0 commit comments

Comments
 (0)