The app I am working on consists of one large custom view that fills the screen. I placed one button in the center of each side of the custom view that can be used to move the drawn object in that direction. Think of the custom view as a "viewfinder" of a camera and I would like the user to be able to pan the viewfinder with buttons on all four sides.

The buttons work perfectly, but when one is pressed, the custom view underneath undergoes lots of redrawing (4 redraws instead of 1) and the UI lags quite a bit.

Is there some way to stop the custom view from redrawing because of a button's animation?

Forgive me if I am missing something obvious.

Thanks in advance for any help... Android rocks!!!

XML Layout:

    <?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>
有帮助吗?

解决方案 2

I found that I was actually making my calculations too accurate and was working my poor Droid too hard. Everything draws smoothly now.

其他提示

Why are the buttons part of the custom view? Why not make them part of your activities layout, so that the layout consists of all the buttons and your custom view?

This may not completely solve your problem, since you may need to further optimize/rethink how your custom view is implemented if invoking its onDraw method blocks the UI thread.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top