2015-10-29 17 views
1

我在XML圖像視圖,我想嘗試設置圖像中心:圖像位置不能夠設置與規模型矩陣中心

我當前的代碼:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:gravity="center" 
       android:orientation="vertical" 
    > 

    <ImageView 
     android:id="@+id/imageview_fullscreen" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:adjustViewBounds="true" 
     android:scaleType="matrix" 
     android:src="@drawable/ic_launcher" 

     /> 

</RelativeLayout> 

我已經加入在縮放功能/縮小圖像視圖 -

http://stackoverflow.com/questions/15609845/add-limit-to-zoom-in-and-zoom-out-in-android

當我寫上面的代碼則圖像不能在中心設置有刻度型matrix。圖像從上方代碼左上方設置。

如何將其設置爲刻度類型爲matrix的中心。 ?

回答

0
<?xml version="1.0" encoding="utf-8"?> 
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="vertical" > 

<ImageView 
    android:id="@+id/imageView1" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:src="@drawable/ic_launcher" /> 

</FrameLayout> 

試試這個。編輯答案。

+0

這是工作,但我已經在輸入/輸出從這個'http://stackoverflow.com/questions/15609845/add-limit-to-zoom-in-and-zoom-out-in-應用ZOON android'。所以當我放大/縮小時,它並不完美。 – deepak

+0

你的問題是你想在中心設置圖像。你應該描述整個問題。 – DroidAks

+0

我很抱歉。我有更新我的問題。 – deepak

0

對於ImageView,添加android:layout_centerInParent="true"

+1

不工作.... – deepak

1

您可以使用

android:layout_gravity="center_vertical" 

並設置

android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
0

試試這個

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:gravity="center" 
    android:orientation="vertical" > 

<ImageView 
    android:id="@+id/imageview_fullscreen" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_centerHorizontal="true" 
    android:layout_centerVertical="true" 
    android:src="@drawable/ic_launcher" /> 

</RelativeLayout> 
0

您提到,您使用的視圖縮放。 如果您正在使用多點觸控來放大ImageView,請在視圖的onMeasure方法 期間調整其大小並居中繪製的圖像。

按照此示例在圖像視圖上實現單點觸摸和多點觸摸,圖像將自動重新調整大小和合身中心。 此外,您可以將父級更改爲FrameLayout以實現縮放許多視圖。 http://www.mobile-open.com/2015/66671.html

0
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT); 
     zoomImageView.setLayoutParams(params); 
     RectF drawableRect = new RectF(0, 0, zoomImageView.getDrawable().getIntrinsicWidth(), zoomImageView.getDrawable().getIntrinsicHeight()); 
     RectF viewRect = new RectF(0, 0, width, (height) - 100); 
     matrix.setRectToRect(drawableRect, viewRect, Matrix.ScaleToFit.CENTER); 
     //matrix.setScale(-1,-1); 
     view.setScaleType(ImageView.ScaleType.MATRIX); 
     zoomImageView.setImageMatrix(matrix); 


    <ImageView 
     android:id="@+id/zoomImage" 
     android:layout_width="200dp" 
     android:layout_height="200dp" 
     android:layout_centerVertical="true" 
     android:layout_centerHorizontal="true" 
     android:src="@mipmap/ic_launcher" /> 

首先在佈局發生在中心的形象,當everr用戶觸動了首次imaageview使ImageView的寬度和高度matchparent,並設置Scaletype矩陣,並應用矩陣。

這裏寬度和高度是設備的寬度和高度,我們可以使用下面的代碼片段。

DisplayMetrics displayMetrics = getApplicationContext().getResources().getDisplayMetrics(); 
    width = displayMetrics.widthPixels; 
    height = displayMetrics.heightPixels;