2011-01-29 52 views
1

我正在處理的應用程序由一個大屏幕自定義視圖組成。我在自定義視圖每邊的中心放置了一個按鈕,可用於在該方向上移動繪製的對象。將自定義視圖看作是相機的「取景器」,我希望用戶能夠用四面的按鈕平移取景器。在視圖頂部繪製按鈕的最有效方法?

這些按鈕可以很好地工作,但是當按下按鈕時,下面的自定義視圖會經歷很多重繪(4次重繪而不是1次),並且UI滯後很多。

是否有某種方法來阻止自定義視圖因重新繪製按鈕的動畫?

原諒我,如果我失去了一些明顯的東西。

預先感謝任何幫助... Android的岩石!

XML佈局:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    > 
    <com.app.CustomView 
    android:id="@+id/CustomView" android:layout_above="@+id/menuButton" android:layout_height="fill_parent" android:layout_width="fill_parent"/> 
    <Button android:layout_height="wrap_content" android:layout_below="@+id/CustomView" android:layout_width="wrap_content" android:layout_alignRight="@+id/CustomView" android:id="@+id/toolsButton" android:text="Tools" android:textSize="24sp"></Button> 
    <Button android:layout_height="wrap_content" android:id="@+id/outButton" android:text="-" android:textSize="30sp" android:layout_toLeftOf="@+id/inButton" android:layout_alignTop="@+id/inButton" android:layout_width="40sp"></Button> 
    <Button android:layout_height="wrap_content" android:layout_alignRight="@+id/CustomView" android:layout_alignBottom="@+id/CustomView" android:text="+" android:textSize="30sp" android:id="@+id/inButton" android:layout_width="wrap_content"></Button> 
    <Button android:layout_alignTop="@+id/CustomView" android:layout_centerHorizontal="true" android:layout_height="40sp" android:layout_width="60sp" android:text="^" android:id="@+id/upButton"></Button> 
    <Button android:layout_alignBottom="@+id/CustomView" android:layout_centerHorizontal="true" android:text="v" android:layout_height="40sp" android:layout_width="60sp" android:id="@+id/downButton"></Button> 
    <Button android:layout_alignRight="@+id/CustomView" android:text="&gt;" android:id="@+id/rightButton" android:layout_height="60sp" android:layout_width="40sp" android:layout_centerVertical="true"></Button> 
    <Button android:id="@+id/leftButton" android:text="&lt;" android:layout_height="60sp" android:layout_width="40sp" android:layout_centerVertical="true"></Button> 
    <Button android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_alignLeft="@+id/CustomView" android:id="@+id/menuButton" android:textSize="24sp" android:text="Functions" android:layout_alignParentBottom="true"></Button> 

</RelativeLayout> 

回答

0

我發現我實際上使得我的計算過於精確,並且努力工作我可憐的Droid。現在一切順利。

0

爲什麼自定義視圖的按鈕部分?爲什麼不讓他們成爲你的活動佈局的一部分,這樣佈局就包含了所有的按鈕和你的自定義視圖?

這可能不會完全解決您的問題,因爲如果調用onDraw方法阻止UI線程,您可能需要進一步優化/重新考慮如何實現自定義視圖。

+0

對不起,如果我不清楚,按鈕是佈局的一部分,而不是自定義視圖,但他們是在自定義視圖的頂部。 – 2011-01-29 19:25:45