다음 코드를 작성하여 Canvas를 사용하여 막 대형 차트 및 원형 차트를 만듭니다.Android에서 스크롤보기에보기를 추가하는 방법은 무엇입니까?
여기에 위의 코드 만 막대 그래프를 보여 내 코드
public class ChartDemo extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//ScrollView sv = new ScrollView(this);
LinearLayout llay = new LinearLayout(this);
llay.setOrientation(LinearLayout.VERTICAL);
float[] values = { 50, 100, 50, 20, 30, 60, 100, 90 };
// Bar Chart
BarGraph BarChart = new BarGraph(this, values);
llay.addView(BarChart);
//Pie Chart
PieChartView Pie = new PieChartView(this, values);
llay.addView(Pie);
//sv.addView(llay);
setContentView(llay);
//setContentView(sv);
}
}
입니다. 나는 아무 오류 및 예외
public class ChartDemo extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ScrollView sv = new ScrollView(this);
LinearLayout llay = new LinearLayout(this);
llay.setOrientation(LinearLayout.VERTICAL);
float[] values = { 50, 100, 50, 20, 30, 60, 100, 90 };
// Bar Chart
BarGraph BarChart = new BarGraph(this, values);
llay.addView(BarChart);
//Pie Chart
PieChartView Pie = new PieChartView(this, values);
llay.addView(Pie);
sv.addView(llay);
setContentView(sv);
}
}
밖으로 only.With는 IT가 블랙을 제공합니다 다음 (빈) 화면과 같은 코드를 변경 그리고 난 내가해야 할 다음
public class PieChartView extends View {
private float[] Values;
public PieChartView(Context context, float[] Values) {
super(context);
this.Values = Values;
}
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
.......
.........
}
}
처럼 내 차트 뷰를 생성 스크롤보기가있는 단일 화면에 두 차트를 모두 추가하십시오. 그러나 나는 이것을 하나의 Activity.How에 추가 할 수 없다.
BarGraph BarChart = new BarGraph(this, values);
// be sure to use correct layout params for your layout
LinearLayout.LayoutParams llp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
llp.weight = 1.0f;
BarChart.setLayoutParams(llp);
llay.addView(BarChart);
FrameLayout.LayoutParams flp = new /* ... */;
llay.setLayoutParams(flp);
sv.addView(llay);
경우 :
"할 수 없다"는 의미를 조금 더 자세히 설명해 주시겠습니까? 약간의 오류가 있거나 전혀 나타나지 않습니까? – Juhani
LinearLayout을 ScrollView에 추가하면 Black Screen Only sv.addView (llay)가 나타납니다. setContentView (sv); –