Skip to content

Commit da7c1a2

Browse files
committed
fix padding bug, add 3 preset indicator style
1 parent 14b07c3 commit da7c1a2

File tree

4 files changed

+96
-40
lines changed

4 files changed

+96
-40
lines changed

demo/src/main/res/layout/activity_main.xml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,13 @@
3535
custom:unselected_height="6dp"
3636
android:layout_marginBottom="20dp"
3737
/>
38-
38+
<com.daimajia.slider.library.Indicators.PagerIndicator
39+
android:id="@+id/custom_indicator_2"
40+
style="@style/AndroidImageSlider_Magnifier_Oval_Black"
41+
android:layout_centerHorizontal="true"
42+
android:layout_alignParentBottom="true"
43+
android:layout_marginBottom="20dp"
44+
/>
3945
<ListView
4046
android:layout_below="@+id/slider"
4147
android:id="@+id/transformers"

library/src/main/java/com/daimajia/slider/library/Indicators/PagerIndicator.java

Lines changed: 17 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -158,20 +158,15 @@ public PagerIndicator(Context context, AttributeSet attrs) {
158158
mPadding_top = attributes.getDimensionPixelSize(R.styleable.PagerIndicator_padding_top,(int)pxFromDp(0));
159159
mPadding_bottom = attributes.getDimensionPixelSize(R.styleable.PagerIndicator_padding_bottom,(int)pxFromDp(0));
160160

161-
mPadding_left = attributes.getDimensionPixelSize(R.styleable.PagerIndicator_padding_left,(int)pxFromDp(3));
162-
mPadding_right = attributes.getDimensionPixelSize(R.styleable.PagerIndicator_padding_right,(int)pxFromDp(3));
163-
mPadding_top = attributes.getDimensionPixelSize(R.styleable.PagerIndicator_padding_top,(int)pxFromDp(0));
164-
mPadding_bottom = attributes.getDimensionPixelSize(R.styleable.PagerIndicator_padding_bottom,(int)pxFromDp(0));
161+
mSelectedPadding_Left = attributes.getDimensionPixelSize(R.styleable.PagerIndicator_selected_padding_left,(int)mPadding_left);
162+
mSelectedPadding_Right = attributes.getDimensionPixelSize(R.styleable.PagerIndicator_selected_padding_right,(int)mPadding_right);
163+
mSelectedPadding_Top = attributes.getDimensionPixelSize(R.styleable.PagerIndicator_selected_padding_top,(int)mPadding_top);
164+
mSelectedPadding_Bottom = attributes.getDimensionPixelSize(R.styleable.PagerIndicator_selected_padding_bottom,(int)mPadding_bottom);
165165

166-
mSelectedPadding_Left = attributes.getDimensionPixelSize(R.styleable.PagerIndicator_selected_padding_left,(int)pxFromDp(3));
167-
mSelectedPadding_Right = attributes.getDimensionPixelSize(R.styleable.PagerIndicator_selected_padding_right,(int)pxFromDp(3));
168-
mSelectedPadding_Top = attributes.getDimensionPixelSize(R.styleable.PagerIndicator_selected_padding_top,(int)pxFromDp(0));
169-
mSelectedPadding_Bottom = attributes.getDimensionPixelSize(R.styleable.PagerIndicator_selected_padding_bottom,(int)pxFromDp(0));
170-
171-
mUnSelectedPadding_Left = attributes.getDimensionPixelSize(R.styleable.PagerIndicator_unselected_padding_left,(int)pxFromDp(3));
172-
mUnSelectedPadding_Right = attributes.getDimensionPixelSize(R.styleable.PagerIndicator_unselected_padding_right,(int)pxFromDp(3));
173-
mUnSelectedPadding_Top = attributes.getDimensionPixelSize(R.styleable.PagerIndicator_unselected_padding_top,(int)pxFromDp(0));
174-
mUnSelectedPadding_Bottom = attributes.getDimensionPixelSize(R.styleable.PagerIndicator_unselected_padding_bottom,(int)pxFromDp(0));
166+
mUnSelectedPadding_Left = attributes.getDimensionPixelSize(R.styleable.PagerIndicator_unselected_padding_left,(int)mPadding_left);
167+
mUnSelectedPadding_Right = attributes.getDimensionPixelSize(R.styleable.PagerIndicator_unselected_padding_right,(int)mPadding_right);
168+
mUnSelectedPadding_Top = attributes.getDimensionPixelSize(R.styleable.PagerIndicator_unselected_padding_top,(int)mPadding_top);
169+
mUnSelectedPadding_Bottom = attributes.getDimensionPixelSize(R.styleable.PagerIndicator_unselected_padding_bottom,(int)mPadding_bottom);
175170

176171
mSelectedLayerDrawable = new LayerDrawable(new Drawable[]{mSelectedGradientDrawable});
177172
mUnSelectedLayerDrawable = new LayerDrawable(new Drawable[]{mUnSelectedGradientDrawable});
@@ -183,7 +178,6 @@ public PagerIndicator(Context context, AttributeSet attrs) {
183178
setDefaultUnselectedIndicatorSize(mDefaultUnSelectedWidth,mDefaultUnSelectedHeight,Unit.Px);
184179
setDefaultIndicatorColor(mDefaultSelectedColor, mDefaultUnSelectedColor);
185180
setIndicatorVisibility(mVisibility);
186-
setDefaultPadding(mPadding_left,mPadding_top,mPadding_right,mPadding_bottom,Unit.Px);
187181
setDefaultSelectedPadding(mSelectedPadding_Left,mSelectedPadding_Top,mSelectedPadding_Right,mSelectedPadding_Bottom,Unit.Px);
188182
setDefaultUnSelectedPadding(mUnSelectedPadding_Left,mUnSelectedPadding_Top,mUnSelectedPadding_Right,mUnSelectedPadding_Bottom,Unit.Px);
189183
attributes.recycle();
@@ -194,53 +188,37 @@ public enum Shape{
194188
}
195189

196190
public void setDefaultPadding(float left,float top, float right, float bottom,Unit unit){
191+
setDefaultSelectedPadding(left,top,right,bottom,unit);
192+
setDefaultUnSelectedPadding(left,top,right,bottom,unit);
193+
}
194+
195+
public void setDefaultSelectedPadding(float left,float top, float right, float bottom,Unit unit){
197196
if(unit == Unit.DP){
198197
mSelectedLayerDrawable.setLayerInset(0,
199198
(int)pxFromDp(left),(int)pxFromDp(top),
200199
(int)pxFromDp(right),(int)pxFromDp(bottom));
201-
mUnSelectedLayerDrawable.setLayerInset(0,
202-
(int)pxFromDp(left),(int)pxFromDp(top),
203-
(int)pxFromDp(right),(int)pxFromDp(bottom));
204200
}else{
205201
mSelectedLayerDrawable.setLayerInset(0,
206202
(int)left,(int)top,
207203
(int)right,(int)bottom);
208-
mUnSelectedLayerDrawable.setLayerInset(0,
209-
(int)left,(int)top,
210-
(int)right,(int)bottom);
204+
211205
}
212206
}
213207

214-
public void setDefaultSelectedPadding(float left,float top, float right, float bottom,Unit unit){
208+
public void setDefaultUnSelectedPadding(float left,float top, float right, float bottom, Unit unit){
215209
if(unit == Unit.DP){
216-
mSelectedLayerDrawable.setLayerInset(0,
210+
mUnSelectedLayerDrawable.setLayerInset(0,
217211
(int)pxFromDp(left),(int)pxFromDp(top),
218212
(int)pxFromDp(right),(int)pxFromDp(bottom));
219213

220214
}else{
221-
mSelectedLayerDrawable.setLayerInset(0,
215+
mUnSelectedLayerDrawable.setLayerInset(0,
222216
(int)left,(int)top,
223217
(int)right,(int)bottom);
224218

225219
}
226220
}
227221

228-
public void setDefaultUnSelectedPadding(float left,float top, float right, float bottom,Unit unit){
229-
if(mUserSetSelectedIndicatorResId == 0){
230-
if(unit == Unit.DP){
231-
mUnSelectedLayerDrawable.setLayerInset(0,
232-
(int)pxFromDp(left),(int)pxFromDp(top),
233-
(int)pxFromDp(right),(int)pxFromDp(bottom));
234-
235-
}else{
236-
mUnSelectedLayerDrawable.setLayerInset(0,
237-
(int)left,(int)top,
238-
(int)right,(int)bottom);
239-
240-
}
241-
}
242-
}
243-
244222
/**
245223
* if you are using the default indicator, this method will help you to set the shape of
246224
* indicator, there are two kind of shapes you can set, oval and rect.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
3+
<item>
4+
<shape android:shape="rectangle">
5+
<corners android:radius="12dp"/>
6+
<solid android:color="#33000000"/>
7+
</shape>
8+
</item>
9+
</layer-list>
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources>
3+
<style name="AndroidImageSlider_Corner_Oval_Orange">
4+
<item name="android:layout_width">wrap_content</item>
5+
<item name="android:layout_height">wrap_content</item>
6+
<item name="android:gravity">center</item>
7+
<item name="android:background">@drawable/indicator_corner_bg</item>
8+
<item name="android:paddingLeft">2dp</item>
9+
<item name="android:paddingRight">2dp</item>
10+
<item name="shape">oval</item>
11+
<item name="padding_left">3dp</item>
12+
<item name="padding_right">3dp</item>
13+
<item name="padding_top">4dp</item>
14+
<item name="padding_bottom">4dp</item>
15+
16+
<item name="selected_color">#f60</item>
17+
<item name="unselected_color">#ffffff</item>
18+
<item name="selected_width">6dp</item>
19+
<item name="selected_height">6dp</item>
20+
<item name="unselected_width">6dp</item>
21+
<item name="unselected_height">6dp</item>
22+
</style>
23+
24+
<style name="AndroidImageSlider_Attractive_Rect_Blue">
25+
<item name="android:layout_width">wrap_content</item>
26+
<item name="android:layout_height">wrap_content</item>
27+
<item name="android:gravity">center</item>
28+
<item name="android:paddingLeft">2dp</item>
29+
<item name="android:paddingRight">2dp</item>
30+
<item name="shape">rect</item>
31+
<item name="padding_left">3dp</item>
32+
<item name="padding_right">3dp</item>
33+
<item name="padding_top">4dp</item>
34+
<item name="padding_bottom">4dp</item>
35+
36+
<item name="selected_color">#30CCE5</item>
37+
<item name="unselected_color">#333333</item>
38+
<item name="selected_width">13dp</item>
39+
<item name="selected_height">4dp</item>
40+
<item name="unselected_width">13dp</item>
41+
<item name="unselected_height">4dp</item>
42+
</style>
43+
44+
<style name="AndroidImageSlider_Magnifier_Oval_Black">
45+
<item name="android:layout_width">wrap_content</item>
46+
<item name="android:layout_height">wrap_content</item>
47+
<item name="android:gravity">center</item>
48+
<item name="android:paddingLeft">2dp</item>
49+
<item name="android:paddingRight">2dp</item>
50+
<item name="shape">oval</item>
51+
<item name="padding_left">3dp</item>
52+
<item name="padding_right">3dp</item>
53+
<item name="padding_top">4dp</item>
54+
<item name="padding_bottom">4dp</item>
55+
56+
<item name="selected_color">#333333</item>
57+
<item name="unselected_color">#33000000</item>
58+
<item name="selected_width">8dp</item>
59+
<item name="selected_height">8dp</item>
60+
<item name="unselected_width">6dp</item>
61+
<item name="unselected_height">6dp</item>
62+
</style>
63+
</resources>

0 commit comments

Comments
 (0)