1111import android .view .View ;
1212
1313import java .util .ArrayList ;
14+ import java .util .Collections ;
1415import java .util .List ;
1516import java .util .Random ;
1617
@@ -46,7 +47,7 @@ public ScrollingImageView(Context context, AttributeSet attrs) {
4647 randomness = getResources ().getIntArray (randomnessResourceId );
4748 }
4849
49- int type = ta .peekValue (R .styleable .ParallaxView_src ).type ;
50+ int type = isInEditMode () ? TypedValue . TYPE_STRING : ta .peekValue (R .styleable .ParallaxView_src ).type ;
5051 if (type == TypedValue .TYPE_REFERENCE ) {
5152 int resourceId = ta .getResourceId (R .styleable .ParallaxView_src , 0 );
5253 TypedArray typedArray = getResources ().obtainTypedArray (resourceId );
@@ -81,9 +82,14 @@ public ScrollingImageView(Context context, AttributeSet attrs) {
8182 typedArray .recycle ();
8283 }
8384 } 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+ }
8793 }
8894 } finally {
8995 ta .recycle ();
@@ -103,7 +109,7 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
103109 @ Override
104110 public void onDraw (Canvas canvas ) {
105111 super .onDraw (canvas );
106- if (canvas == null ) {
112+ if (canvas == null || bitmaps . isEmpty () ) {
107113 return ;
108114 }
109115
0 commit comments