2017-04-16 54 views
1

我有一個表面視圖來執行一些繪圖工作。我的視圖支持放大/縮小功能。現在,當用戶通過手勢放大/縮小手指時,我想調整表面視圖的大小,我嘗試通過更改surfaceview的佈局參數來調整大小。儘管這有效,但速度很慢,在做調整工作時,我看到一些大的跳躍(滯後),這是不可用的。在這裏,我想知道如何有效地調整表面視圖的大小(沒有那個跳躍)?在運行時有效更改視圖大小

這裏狙擊我從結構上看,

<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

<FrameLayout 
    android:layout_width="match_parent" 
    android:fillViewport="true" 
    android:layout_above="@+id/bottomMenu" 
    android:layout_height="match_parent"> 

    <MySurfaceView 
     android:layout_gravity="center" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content"/> 
</FrameLayout> ... 

而且PARAMS更改代碼,

ViewGroup.LayoutParams params = surface.getLayoutParams(); 
params.height = (int) (750*factor); 
surface.setLayoutParams(params); 
+0

你有沒有考慮過使用['TextureView'](https://developer.android.com/reference/android/view/TextureView.html)? – azizbekian

+0

請參閱http://stackoverflow.com/a/21282056/4069985 –

回答

0

井,我發現surfaceHolder的方法來設置固定畫布大小年底,

holder.setFixedSize(canvasW, canvasH); 

使用此方法,我可以使用佈局參數調整佈局大小,不會有任何滯後。在這裏,我需要在設置它之前知道畫布的大小,所以我從Java代碼中添加了預定義大小的SurfaceView,並且工作順利。

**我不確定,爲什麼設置畫布固定尺寸完成了這個訣竅。歡迎大家解釋一下(可能是編輯這個答案)。

+0

請問您可以添加更多詳細信息您是如何做到的?在改變佈局滯後的情況下調整SurfaceView時,我面臨同樣的問題。 – vovan888

+0

初始化surfaceHolder時,通過上述方法設置它的大小。 – asish