Skip to content

Commit 3b189d8

Browse files
committed
Update 1.1.2
1 parent f62836d commit 3b189d8

2 files changed

Lines changed: 16 additions & 10 deletions

File tree

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@ limitations under the License.
2828
android:id="@+id/img_vertical_slide"
2929
android:layout_width="match_parent"
3030
android:layout_height="0dp"
31-
android:layout_weight="1"
32-
slide:source="@drawable/long_background"
33-
slide:axis="vertical"/>
31+
android:layout_weight="1"/>
3432

3533
<com.gigamole.slideimageview.lib.SlideImageView
3634
android:id="@+id/img_horizontal_slide"

library/src/main/java/com/gigamole/slideimageview/lib/SlideImageView.java

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -111,21 +111,20 @@ private void setAxis(int axis) {
111111

112112
public void setSource(Drawable source) {
113113
this.bitmap = ((BitmapDrawable) source).getBitmap();
114+
requestLayout();
114115
}
115116

116117
public void setSource(Bitmap source) {
117118
this.bitmap = source;
119+
requestLayout();
118120
}
119121

120122
public void setSource(int sourceId) {
121123
this.bitmap = ((BitmapDrawable) getResources().getDrawable(sourceId)).getBitmap();
124+
requestLayout();
122125
}
123126

124-
@Override
125-
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
126-
this.width = w;
127-
this.height = h;
128-
127+
private void createSource() {
129128
if (this.bitmap != null) {
130129
if (this.axis == Axis.HORIZONTAL) {
131130
this.bitmap = Bitmap.createScaledBitmap(
@@ -143,10 +142,19 @@ protected void onSizeChanged(int w, int h, int oldw, int oldh) {
143142
this.slideSize = (this.bitmap.getHeight() - this.height) * -1;
144143
}
145144
} else {
146-
throw new NullPointerException(getContext().getString(R.string.source_error));
145+
this.bitmap = Bitmap.createBitmap(this.width, this.height, Bitmap.Config.ARGB_8888);
147146
}
147+
}
148+
149+
@Override
150+
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
151+
this.width = MeasureSpec.getSize(widthMeasureSpec);
152+
this.height = MeasureSpec.getSize(heightMeasureSpec);
153+
154+
createSource();
148155

149-
super.onSizeChanged(w, h, oldw, oldh);
156+
this.setMeasuredDimension(this.width, this.height);
157+
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
150158
}
151159

152160
@Override

0 commit comments

Comments
 (0)