显色与viewflipper surfaceview问题? [英] rendaring issue with surfaceview in viewflipper?

查看:180
本文介绍了显色与viewflipper surfaceview问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在通过扩展surfaceview以饼图级拉丝饼图。现在我创造的饼图2对象和增加一个VieWFlipper这些图表之间刷卡。我现在的问题是,如果用户扫描到第二个观点饼图第二个是不是对用户可见。但所有的第二个馅饼的功能是否正常。我想到像surfaceview其刷新问题。

i am drawing a piechart by extending surfaceview to PieChart Class. now i am creating 2 objects for Piechart and adding to a VieWFlipper to swipe between those charts. now my problem is 2nd Piechart is not visible to the user if user swipes to 2nd view. but all the 2nd pies functionality is working. i am thinking like its refresh problem of the surfaceview.

在这个任何帮助将AP preciable。以下是我的饼图类。

any help on this will be appreciable. the following is my PieChart class.

class MyPieChart extends SurfaceView implements SurfaceHolder.Callback {

    @Override
    public void onDraw(Canvas canvas) {
        if (hasData) {
            resetColor();
            try {
                canvas.drawColor(getResources().getColor(R.color.graphbg_color));

                graphDraw(canvas);
            } catch (ValicException ex) {

            }

        }
    }

    @Override
    public void surfaceChanged(SurfaceHolder holder, int format, int width,
            int height) {

        Log.i("PieChart", "surfaceChanged");

    }

    public int callCount = 0;

    @Override
    public void surfaceCreated(SurfaceHolder holder) {
        if ((callCount++) % 2 == 0) {
            callCount = 1;
            try {
                 Log.i("PieChart", "surfaceCreated");
                mChartThread = new ChartThread(getHolder(), this);
                mChartThread.setRunning(true);

                if (!mChartThread.isAlive()) {
                    mChartThread.start();
                }

                mFrame = holder.getSurfaceFrame();

                mOvalF = new RectF(0, 0, mFrame.right, mFrame.right);

            } catch (Exception e) {
                // No error message required
            }
        }
    }

    @Override
    public void surfaceDestroyed(SurfaceHolder holder) {
         Log.i("PieChart", "surfaceDestroyed");
        boolean retry = true;
        callCount = 0;
        mChartThread.setRunning(false);
        while (retry) {
            try {
                mChartThread.join();
                retry = false;
            } catch (InterruptedException e) {
                // No error message required
            }
        }
    }
}

class ChartThread extends Thread {
    private SurfaceHolder mSurfaceHolder;
    private PieChart mPieChart;
    private boolean mRefresh = false;

    public ChartThread(SurfaceHolder surfaceHolder, PieChart pieChart) {
        // Log.i("ChartThread", "ChartThread");
        mSurfaceHolder = surfaceHolder;
        mPieChart = pieChart;
    }

    public void setRunning(boolean Refresh) {
        // Log.i("ChartThread", "setRunning : " + Refresh);
        mRefresh = Refresh;
    }

    @Override
    public void run() {
        Canvas c;
        // Log.i("ChartThread", "run : " + mRefresh);
        while (mRefresh) {
            c = null;
            try {
                c = mSurfaceHolder.lockCanvas(mPieChart.mFrame);
            //  c.drawColor(0xFFebf3f5);
                synchronized (mSurfaceHolder) {

                    mPieChart.onDraw(c);

                }
            } catch (Exception ex) {

            } finally {
                // do this in a finally so that if an exception is thrown
                // during the above, we don't leave the Surface in an
                // inconsistent state
                if (c != null) {
                    mSurfaceHolder.unlockCanvasAndPost(c);
                }
            }
        }
    }
}

这是我的flipper.xml

here is my flipper.xml

<ViewFlipper  
android:id="@+id/flipper"
android:layout_width="fill_parent" 
android:layout_height="fill_parent" > 

<LinearLayout  android:id="@+id/pie1" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" />

<LinearLayout android:id="@+id/pie2" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" />

在这里我是我的活动

public class ViewFlipperActivity extends Activity {
    Button b1;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        b1 = (Button)findViewById(R.id.submit1);

        b1.setOnClickListener(new View.OnClickListener() {
            ViewFlipper vflipper=(ViewFlipper)findViewById(R.id.flipper);   
            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub

                vflipper.showNext();

            }
        });

    }

,我dding的扇形图在翻转PIE1和PIE2 LinearLayouts。

and i am dding the piecharts to Pie1 and Pie2 LinearLayouts in the Flipper.

两者都创造了馅饼的并粘贴到馅饼布局。现在,如果我移动到第二个观点升降舵PIE1是显示的,而不是PIE2和所有其他数据和我收到涉及到PIE2功能。我的疑问是PIE2被渲染和PIE1下隐藏。任何一个可以帮助我在此有一些解决方案。

both the pie's are created and pasted on to the Pie Layouts. now if i move to the 2nd view in the flipper Pie1 is showing instead of pie2 and all other data and functionality which i am getting is related to Pie2. my doubt is Pie2 is rendering and hidden under Pie1. can any one help me on this with some solution.

我经历了这个问题得到了休息。这引起了以下改变的另一个问题。

i got a break through for this issue. which caused another issue with the following changes.

在flipper.xml取代的LinearLayout我的地方观看的鳍状肢的。

in flipper.xml replaced LinearLayout i place of view flipper.

    <LinearLayout  
    android:id="@+id/flipper"
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" > 

    <LinearLayout  android:id="@+id/pie1" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" />

   </LinearLayout  >

和在ViewFlipperActivity

and in ViewFlipperActivity

    public class ViewFlipperActivity extends Activity {
        Button b1;

        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);

            b1 = (Button)findViewById(R.id.submit1);

            b1.setOnClickListener(new View.OnClickListener() {
                LinearLayout vflipper=(LinearLayout)findViewById(R.id.flipper); 
LinearLayout pie1=(LinearLayout)findViewById(R.id.pie1);    
                @Override
                public void onClick(View v) {
                    // TODO Auto-generated method stub

                    vflipper.setAnimation(AnimationUtils.loadAnimation(this, R.anim.push_left_in));

pie1.removeAllViews();
pie1.addView(PieChart/SurfaceView);

                }
            });

        }

在动画和工作正常和饼图是越来越的看法改变了。但块矩形是从surfaceview一秒钟之间的扇形图刷卡时越来越明显。可以有人帮助我在这个问题上。

with the animation and is working fine and piechart is getting changed on the view. but block rect is getting visible from the surfaceview for a sec when swiping between piecharts. can some one help me on this issue.

推荐答案

在这里的主要问题是SurfaceView不能动画。这就是为什么无论ViewFlipper也不布局动画不能应用于SurfaceView。

here main problem is SurfaceView cannot be animated. that's why neither ViewFlipper nor Layout Animation cannot be applied for SurfaceView.

这篇关于显色与viewflipper surfaceview问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆