11
11
import android .view .View ;
12
12
13
13
import java .util .ArrayList ;
14
+ import java .util .Collections ;
14
15
import java .util .List ;
15
16
import java .util .Random ;
16
17
@@ -46,7 +47,7 @@ public ScrollingImageView(Context context, AttributeSet attrs) {
46
47
randomness = getResources ().getIntArray (randomnessResourceId );
47
48
}
48
49
49
- int type = ta .peekValue (R .styleable .ParallaxView_src ).type ;
50
+ int type = isInEditMode () ? TypedValue . TYPE_STRING : ta .peekValue (R .styleable .ParallaxView_src ).type ;
50
51
if (type == TypedValue .TYPE_REFERENCE ) {
51
52
int resourceId = ta .getResourceId (R .styleable .ParallaxView_src , 0 );
52
53
TypedArray typedArray = getResources ().obtainTypedArray (resourceId );
@@ -81,9 +82,14 @@ public ScrollingImageView(Context context, AttributeSet attrs) {
81
82
typedArray .recycle ();
82
83
}
83
84
} else if (type == TypedValue .TYPE_STRING ) {
84
- bitmaps = singletonList (BitmapFactory .decodeResource (getResources (), ta .getResourceId (R .styleable .ParallaxView_src , 0 )));
85
- scene = new int []{0 };
86
- maxBitmapHeight = bitmaps .get (0 ).getHeight ();
85
+ final Bitmap bitmap = BitmapFactory .decodeResource (getResources (), ta .getResourceId (R .styleable .ParallaxView_src , 0 ));
86
+ if (bitmap != null ) {
87
+ bitmaps = singletonList (bitmap );
88
+ scene = new int []{0 };
89
+ maxBitmapHeight = bitmaps .get (0 ).getHeight ();
90
+ } else {
91
+ bitmaps = Collections .emptyList ();
92
+ }
87
93
}
88
94
} finally {
89
95
ta .recycle ();
@@ -103,7 +109,7 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
103
109
@ Override
104
110
public void onDraw (Canvas canvas ) {
105
111
super .onDraw (canvas );
106
- if (canvas == null ) {
112
+ if (canvas == null || bitmaps . isEmpty () ) {
107
113
return ;
108
114
}
109
115
0 commit comments