2011-01-29 72 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

相关问题