|
|
@@ -5,7 +5,6 @@ import android.content.Context;
|
|
|
import android.graphics.Bitmap;
|
|
|
import android.graphics.BitmapFactory;
|
|
|
import android.util.AttributeSet;
|
|
|
-import android.util.Log;
|
|
|
import android.view.animation.Animation;
|
|
|
import android.view.animation.TranslateAnimation;
|
|
|
import android.widget.FrameLayout;
|
|
|
@@ -38,8 +37,6 @@ public class ScalableImageView extends AppCompatImageView implements IScalable {
|
|
|
private int mHorizontalRawHeight;
|
|
|
private Bitmap mHorizontalBitmap;
|
|
|
|
|
|
- private int parentWidth;
|
|
|
- private int parentHeight;
|
|
|
|
|
|
public ScalableImageView(@NonNull Context context) {
|
|
|
this(context, null);
|
|
|
@@ -51,7 +48,6 @@ public class ScalableImageView extends AppCompatImageView implements IScalable {
|
|
|
|
|
|
public ScalableImageView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
|
|
|
super(context, attrs, defStyleAttr);
|
|
|
-
|
|
|
post(() -> {
|
|
|
BitmapFactory.Options verticalOptions = new BitmapFactory.Options();
|
|
|
// verticalOptions.inJustDecodeBounds = true;
|
|
|
@@ -65,10 +61,6 @@ public class ScalableImageView extends AppCompatImageView implements IScalable {
|
|
|
mHorizontalRawWidth = horizontalOptions.outWidth * 2;
|
|
|
mHorizontalRawHeight = horizontalOptions.outHeight * 2;
|
|
|
|
|
|
- FrameLayout frameLayout = (FrameLayout)getParent();
|
|
|
- parentWidth = frameLayout.getWidth();
|
|
|
- parentHeight = frameLayout.getHeight();
|
|
|
-
|
|
|
setImageBitmap(mVerticalBitmap);
|
|
|
AnimateManager.getInstance().register(this);
|
|
|
});
|
|
|
@@ -88,26 +80,29 @@ public class ScalableImageView extends AppCompatImageView implements IScalable {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- setImageBitmap(mHorizontalBitmap);
|
|
|
-
|
|
|
- this.height = bottom-top;
|
|
|
- width = (height * mHorizontalRawWidth)/ mHorizontalRawHeight;
|
|
|
+ // 需要在post里执行,否则setMinimumWidth或者setLayoutParams都不起作用
|
|
|
+ post(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ height = bottom-top;
|
|
|
+ width = (height * mHorizontalRawWidth)/ mHorizontalRawHeight;
|
|
|
|
|
|
+ //int minWidth = width < mHorizontalRawWidth ? mHorizontalRawWidth : width;
|
|
|
+ setMinimumWidth(width);
|
|
|
+ setMaxWidth(width);
|
|
|
|
|
|
- int minWidth = width < mHorizontalRawWidth ? mHorizontalRawWidth : width;
|
|
|
- setMinimumWidth(minWidth);
|
|
|
- setMaxWidth(minWidth);
|
|
|
+ //int minHeight = height < mHorizontalRawHeight ? mHorizontalRawHeight : height;
|
|
|
+ setMinimumHeight(height);
|
|
|
+ setMaxHeight(height);
|
|
|
|
|
|
- int minHeight = height < mHorizontalRawHeight ? mHorizontalRawHeight : height;
|
|
|
- setMinimumHeight(minHeight);
|
|
|
- setMaxHeight(minHeight);
|
|
|
- Log.e(TAG, "min_width:" + minWidth);
|
|
|
- Log.e(TAG, "min_height:" + minHeight);
|
|
|
-// FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) getLayoutParams();
|
|
|
-// params.width = width;
|
|
|
-// params.height = h;
|
|
|
+ FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) getLayoutParams();
|
|
|
+ params.width = width;
|
|
|
+ params.height = height;
|
|
|
+ setImageBitmap(mHorizontalBitmap);
|
|
|
|
|
|
- startHorizontalAnimation(left, right-width, top);
|
|
|
+ startHorizontalAnimation(left, right-width, top);
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -116,25 +111,26 @@ public class ScalableImageView extends AppCompatImageView implements IScalable {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- setImageBitmap(mVerticalBitmap);
|
|
|
+ post(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ width = right-left;
|
|
|
+ height = (width * mVerticalRawHeight)/ mVerticalRawWidth;
|
|
|
|
|
|
- this.width = right-left;
|
|
|
- height = (width * mVerticalRawHeight)/ mVerticalRawWidth;
|
|
|
+ setMinimumWidth(width);
|
|
|
+ setMaxWidth(width);
|
|
|
|
|
|
- int minWidth = width < mVerticalRawWidth ? mVerticalRawWidth : width;
|
|
|
- setMinimumWidth(minWidth);
|
|
|
- setMaxWidth(minWidth);
|
|
|
+ setMinimumHeight(height);
|
|
|
+ setMaxHeight(height);
|
|
|
|
|
|
- int minHeight = height < mVerticalRawHeight ? mVerticalRawHeight : height;
|
|
|
- setMinimumHeight(minHeight);
|
|
|
- setMaxHeight(minHeight);
|
|
|
- Log.e(TAG, "min_width:" + minWidth);
|
|
|
- Log.e(TAG, "min_height:" + minHeight);
|
|
|
-// FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) getLayoutParams();
|
|
|
-// params.width = w;
|
|
|
-// params.height = height;
|
|
|
+ FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) getLayoutParams();
|
|
|
+ params.width = width;
|
|
|
+ params.height = height;
|
|
|
|
|
|
- startVerticalAnimation(top, bottom-height, left);
|
|
|
+ setImageBitmap(mVerticalBitmap);
|
|
|
+ startVerticalAnimation(top, bottom-height, left);
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
private Animation animation;
|