@@ -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