我是靠谱客的博主 机智草莓,最近开发中收集的这篇文章主要介绍Android 图片放大显示,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

  在AndroidManifest配置

<activity

android:name=".ui.RealShowImageActivity"

android:configChanges="keyboardHidden|orientation|screenSize"

android:theme="@style/IMTheme.Transparent"

android:exported="true"

android:screenOrientation="portrait"/>

接着在styles.xml中设置
<style name="IMTheme.Basic" parent="android:Theme.Translucent">
<item name="android:windowNoTitle">true</item>
<item name="android:windowContentOverlay">@null</item>
</style>
<style name="IMTheme.Transparent" parent="@style/IMTheme.Basic">
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowIsTranslucent">true</item>
</style>
点击图片时
Bundle bundle = new Bundle();
int[] location = new int[2];
imageView.getLocationOnScreen(location);//imageView要放大的图片
bundle.putInt("locationX", location[0]);
bundle.putInt("locationY", location[1]);
bundle.putInt("height", imageView.getHeight());
bundle.putInt("width", imageView.getWidth());
bundle.putString("url",items.getPicture());//图片的url
Intent intent = new Intent(MainActivity.this,RealShowImageActivity.class);
intent.putExtras(bundle);
startActivity(intent);
overridePendingTransition(0, 0);

RealShowImageActivity
public class RealShowImageActivity extends BaseActivity {
private int mLocationX;

private int mLocationY;

private int mWidth;

private int mHeight;

SmoothImageView imageView = null;

String url;

@Override

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

mLocationX = getIntent().getIntExtra("locationX", 0);

mLocationY = getIntent().getIntExtra("locationY", 0);

mWidth = getIntent().getIntExtra("width", 0);

mHeight = getIntent().getIntExtra("height", 0);

url = getIntent().getStringExtra("url");

imageView = new SmoothImageView(this);

imageView.setOriginalInfo(mWidth, mHeight, mLocationX, mLocationY);

imageView.transformIn();

imageView.setLayoutParams(new ViewGroup.LayoutParams(-1, -1));

imageView.setScaleType(ImageView.ScaleType.FIT_CENTER);

setContentView(imageView);

ImageLoader imageLoader = TakeOutVolley.getImageLoader();

try {
imageLoader.get(url, com.android.volley.toolbox.ImageLoader.getImageListener(imageView, R.drawable.icon_caipin, R.drawable.icon_caipin));

} catch (OutOfMemoryError o) {
imageView.setBackgroundResource(R.drawable.icon_caipin);

}
}
@Override

public boolean onTouchEvent(MotionEvent event) {
// TODO Auto-generated method stub

onBackPressed();

return true;

}
@Override

protected void onPause() {
super.onPause();

if (isFinishing()) {
overridePendingTransition(0, 0);

}
}
@Override

public void onBackPressed() {
imageView.setOnTransformListener(new SmoothImageView.TransformListener() {
@Override

public void onTransformComplete(int mode) {
if (mode == 2) {
finish();

}
}
});

imageView.transformOut();

}
}



最后

以上就是机智草莓为你收集整理的Android 图片放大显示的全部内容,希望文章能够帮你解决Android 图片放大显示所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(48)

评论列表共有 0 条评论

立即
投稿
返回
顶部