两款显卡在一个屏幕 [英] Two graphics in one screen

查看:222
本文介绍了两款显卡在一个屏幕的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是想显示在一个屏幕上两个图形,但我不能。这里是code,其中我展示的onClick函数内部一个图形:

 情况下R.id.graphs:
            。GraphicalView mChartView =新需要等级()执行(这一点);
            的LinearLayout布局=(的LinearLayout)findViewById(R.id.graph);
            layout.removeAllViews();
            layout.addView(mChartView,新的LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
            打破;

任何想法??

非常感谢你!


解决方案

 情况下R.id.graphs:
        。GraphicalView mChartView1 =新需要等级()执行(这一点);
        GraphicalView mChartView2 = //另一个chartView创作
        的LinearLayout布局=(的LinearLayout)findViewById(R.id.graph);
        layout.removeAllViews();
        layout.addView(mChartView1,新的LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
        layout.addView(mChartView2,新的LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
        打破;

这应该工作。一定要对不同的ID的 mChartView - 如果你创建它们编程,而不是从XML布局充气,你需要设置id编程太:

  mChartView1.setId(1);
mChartView2.setId(2);

此外, RelativeLayout的可能会为您提供布局和为定位的长期更多的定制。然后,您需要设置在布局PARAMS的相对位置:

  RelativeLayout的布局=(RelativeLayout的)findViewById(R.id.graph);
....
RelativeLayout.LayoutParams paramsForChart2 =新RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,ViewGroup.LayoutParams.WRAP_CONTENT);
paramsForChart2.addRule(RelativeLayout.RIGHT_OF,mChartView1.getId());
layout.addView(mChartView2,paramsForChart2);

I've being trying to display two graphics in one screen but I'm not able. Here is the code where i show one graphic inside the onClick function:

case R.id.graphs:
            GraphicalView mChartView = new Niveau().execute(this);
            LinearLayout layout = (LinearLayout) findViewById(R.id.graph);
            layout.removeAllViews();
            layout.addView(mChartView, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
            break;

Any idea??

Thank you very much!

解决方案

case R.id.graphs:
        GraphicalView mChartView1 = new Niveau().execute(this);
        GraphicalView mChartView2 = //  another chartView creation
        LinearLayout layout = (LinearLayout) findViewById(R.id.graph);
        layout.removeAllViews();
        layout.addView(mChartView1, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
        layout.addView(mChartView2, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
        break;

That should work. Be sure to have different ids on your mChartView - if you create them programmatically and not inflated from an XML layout, you need to set the id programmatically too:

mChartView1.setId(1);
mChartView2.setId(2);

Also, a RelativeLayout would probably offer you more customization in term of layout and positionning. You then need to set the relative positions in your layout params:

RelativeLayout layout = (RelativeLayout) findViewById(R.id.graph);
....
RelativeLayout.LayoutParams paramsForChart2 = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
paramsForChart2.addRule(RelativeLayout.RIGHT_OF, mChartView1.getId());
layout.addView(mChartView2, paramsForChart2);

这篇关于两款显卡在一个屏幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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