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>
4

2 回答 2

0

为什么按钮是自定义视图的一部分?为什么不让它们成为您的活动布局的一部分,以便布局包含所有按钮和您的自定义视图?

onDraw这可能无法完全解决您的问题,因为如果调用其方法阻塞 UI 线程,您可能需要进一步优化/重新考虑如何实现自定义视图。

于 2011-01-29T19:11:51.860 回答
0

我发现我实际上让我的计算太准确了,而且我的可怜的 Droid 工作太辛苦了。现在一切都很顺利。

于 2011-01-30T04:07:53.003 回答