2013-10-03 47 views
0

我有这个活动显示图像,我期待它默认显示在中心,但它是什么使图像显示在屏幕的左上角和时间我按下时间如果去中心的图像。图像默认显示没有得到集中

变焦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(); 
    } 

更新

对不起,我忘了提及,该图像能够放大的。因此,有一个潜在可能 图像将从中心延伸到全屏。

我使用通用-图片下载器来显示图像,并且如果使用一个绘制图像被居中向右走,但如果切换到通用-图像 - 装载机中,首先显示的图像在屏幕的最左边然后如果我触摸它,然后转移到中心。

+0

也删除不必要的'机器人:layout_gravity = “中心” 从'父'FrameLayout'。 –

+0

@RaviBhatt,请看我更新的q。 – rahstame

回答

0

使用android:scaletype="center"

<ImageView 
    android:id="@+id/iv_photo" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_gravity="center" 
    android:scaleType="center"/> 

或使高度和宽度wrap_content然后,将工作根据父视图

<ImageView 
    android:id="@+id/img" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_gravity="center"/> 

这使在中心控制

android:layout_gravity="center" 
+0

对不起,我忘了提及图像可以放大,所以如果我使用解决方案#2,图像仍然限于一种尺寸。 – rahstame

1

尝试使用android:scaleType代替。 (ImageView Scale Type

<ImageView 
    android:id="@+id/iv_photo" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:scaleType="center" /> 
+0

对不起,我忘记提及图像可以放大。 – rahstame

0
<ImageView 
    android:id="@+id/img" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:src="@drawable/ic_launcher" 
    android:layout_gravity="center" /> 

,或者你可以按如下方式使用相对布局..

<ImageView 
    android:id="@+id/img" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_centerHorizontal="true" 
    android:layout_centerVertical="true" 
    android:src="@drawable/ic_launcher" /> 
+0

请参阅我的更新,图像用于放大。 – rahstame

+0

查看我更新的答案我已发布链接并将其标记为答案@lordzden – Hamad