我想在android中繪製一個圖表,併爲此我使用一個圖表(我導入到我的應用程序中的一個jar文件),我通過該值需要顯示...從它的父母中刪除圖表
該圖表存在的問題是它佔用了設置的活動的全屏幕。與整個數據
protected void onProgressUpdate(String...values) {
setContentView(lv);
}
一遍又一遍:
public void onCreate(){
LineView lv;
lv=new LineView(this);
}
,我把圖表上的值是從DB使用異步線程,這樣somwewhere我這樣做readed。
這裏是我的問題:
我試圖用我在其中有一個空白的線性佈局和按鈕(我想設置我的圖表下方的按鈕)的XML文件,我想通過我的圖表LV作爲一個孩子到線性佈局,不佔據了我的整個屏幕:
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">
<LinearLayout
android:id="@+id/titlu"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="250px" >
/>
</LinearLayout>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Stop"
android:gravity="bottom"
android:id="@+id/stop"
/>
當我試圖在的onCreate :
thatlinear=(LinearLayout)findViewById(R.id.titlu);
這:
thatlinear.addView(lv); in my function onProgresssUpdate()
我曾告訴我說我的表,LV,已經有母,爲了將它傳遞給其他錯誤父母我必須刪除最初的父母。
所以...我這樣做:
ViewGroup v=(ViewGroup)(lv.getParent());
v.removeView(lv);
但細想一下,它沒有工作這樣......我在這行有一個FC-java的郎空指針異常:
v.removeView(lv);
而最後這個我想是這樣的:
LinearLayout llay=new LinearLayout(this);
LinearLayout lytContainer = (LinearLayout) View.inflate(
this, R.layout.chart_speed, null);
lytContainer.setLayoutParams(new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.FILL_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT));
llay.addView(lv);
chart_speed是我上面發佈的xml ...
而且它沒有這樣工作....仍然FC。
問:
如何進行,以通過我的圖表作爲一個孩子到線性佈局,所以它不會filll我的整個畫面......我可以把按鈕它下面???
編輯:
我已經做到了這一點:
setContentView(R.layout.chart_speed);
ViewGroup thatlayout=(ViewGroup)findViewById(R.id.titlu);
thatlayout.addView(lv);
chart_speed,是我整個XML titlu的名字是我的LinearLayout的@ + ID ...
而這正是我的logcat顯示:
java.lang.NullPointerException
at com.kidroid.kichart.view.AxisView.GenerateValue(AxisView.java:112)
at com.kidroid.kichart.view.AxisView.drawAxisXY(AxisView.java:61)
at com.kidroid.kichart.view.LineView.onDraw(LineView.java:19)
at android.view.View.draw(View.java:6535)
at android.view.ViewGroup.drawChild(ViewGroup.java:1531)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1258)
0 at android.view.ViewGroup.drawChild(ViewGroup.java:1529)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1258)
at android.view.ViewGroup.drawChild(ViewGroup.java:1529)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1258)
at android.view.View.draw(View.java:6538)
EDIT2:
我在我的ProgressUpdate這樣做(){
// initializating組件
thatlayoyt.add(lv);
}
而對於一個幾秒鐘它會顯示正確的,但在那之後,我得到FC:
java.lang.IllegalStateException:指定的孩子已經有一個父。您必須先調用子對象的父對象的removeView()。
at android.view.ViewGroup.addViewInner(ViewGroup.java:1861)
at android.view.ViewGroup.addView(ViewGroup.java:1756)
在android.view.ViewGroup.addView(ViewGroup.java:1713)
最終版本和它的作品...我不認爲是非常正確的,但它的工作原理:
ViewGroup thatlayout;
公共無效的onCreate(捆綁savedInstanceState){
thatlayout =(的ViewGroup)findViewById(R.id.titlu);
}
保護無效onProgressUpdate(字符串值...){
// initalizating
try{
ViewGroup v=(ViewGroup)(lv.getParent());
v.removeView(lv);
}
catch(Exception e)
{
e.printStackTrace();
}
thatlayout.addView(lv);
}
sa vedem,sa vedem ..... lasa ma un minut sa incerc :) – adrian 2011-06-03 11:59:11
Mi-am editat intrebarea,ai putea sa te uiti?!! Ms :) – adrian 2011-06-03 12:20:58
它看起來像是有問題的習慣零件。在展示之前,你必須做一些初始化工作。請參閱[此鏈接](http://writerbay.net/?p=401)或[這一個](http://stackoverflow.com/questions/6221300/place-a-chart-in-a-view)。 – 2011-06-03 12:29:27