我有这个显示图像的活动,我希望它默认显示在中心但是它变成了图像显示在屏幕的左上角,当我按下图像时,如果时间转到中央。
缩放 xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center" >
<ImageView
android:id="@+id/iv_photo"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center" />
<TextView
android:id="@+id/tv_current_matrix"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center_horizontal"
android:gravity="center"
android:background="#60000000"
android:textColor="@android:color/white" />
</FrameLayout>
活动
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
Window window = getWindow();
window.setGravity(Gravity.CENTER);
imageLoader = ImageLoader.getInstance();
imageLoader.init(ImageLoaderConfiguration.createDefault(getBaseContext()));
Intent intent = getIntent();
easyPuzzle = intent.getExtras().getString("imagePath");
setContentView(R.layout.zoom_image);
mImageView = (ImageView) findViewById(R.id.iv_photo);
mCurrMatrixTv = (TextView) findViewById(R.id.tv_current_matrix);
//aq.id(R.id.iv_photo).image(easyPuzzle.toString(), memCache, fileCache);
Log.d("#Zoom Picture CLass: Image Path ", ""+ easyPuzzle.toString());
//
//mImageView.setImageResource(R.drawable.beverages);
//new DisplayImage(mImageView)
//.execute(easyPuzzle);
DisplayImageOptions options = new DisplayImageOptions.Builder()
//Because you reuse view for different
//images you can see a previous image in the view while new image is loading. .resetViewBeforeLoading(true
.showImageForEmptyUri(R.drawable.content_picture)
.showImageOnFail(R.drawable.content_picture)
.cacheOnDisc(true)
.bitmapConfig(Bitmap.Config.RGB_565)
.build();
if(imageLoader!=null){
imageLoader.displayImage(easyPuzzle.toString(), mImageView, options);
}
// The MAGIC happens here!
mAttacher = new PhotoViewAttacher(mImageView);
// Lets attach some listeners, not required though!
mAttacher.setOnMatrixChangeListener(new MatrixChangeListener());
mAttacher.update();
}
更新
对不起,我忘了提到图像可以放大。所以图像可能会从中心拉伸到全屏。
我正在使用 Universal-Image-Loader 来显示图像,如果我使用可绘制图像,图像会立即居中,但是如果我切换到 Universal-Image-Loader,图像首先会显示在屏幕的最左上角如果我触摸它,则转移到中心。