0
正如我的要求是顯示一個水平圖。我已經創建了該圖。但是我需要在小節前後添加文本,以指示圖中的哪個小節。經過短暫的研究,我沒有想到任何想法。任何人都可以提出一些建議來做到這一點。任何迴應將不勝感激。如何在視圖中的形狀之前動態地添加文本?
這是我的代碼在我的視圖類中繪製形狀。
public class RectangleView extends View{
private ShapeDrawable[] mDrawables1,mDrawables2;
public RectangleView(Context context) {
super(context);
setFocusable(true);
setBackgroundColor(0xFFFFFFFF);
mDrawables1 = new ShapeDrawable[1];
mDrawables2 = new ShapeDrawable[1];
mDrawables1[0] = new ShapeDrawable(new RectShape());
mDrawables2[0] = new ShapeDrawable(new RectShape());
mDrawables1[0].getPaint().setColor(0xFF347235);
mDrawables2[0].getPaint().setColor(0xFF348017);
}
@Override protected void onDraw(Canvas canvas) {
Log.d("0000000","9999999");
for (Drawable dr : mDrawables1) {
int x1 = 10;
int y1 = 45;
int width1 = 200;
int height1 = 20;
dr.setBounds(x1, y1, x1 + width1, y1 + height1);
dr.draw(canvas);
y1 += height1 + 5;
}
for (Drawable dr : mDrawables2) {
int x1 = 10;
int y1 = 20;
int width1 = 200;
int height1 = 20;
dr.setBounds(x1, y1, x1 + width1, y1 + height1);
dr.draw(canvas);
y1 += height1 + 5;
}
}
}
現在我已經在使用addView()方法的活動中添加了這個視圖。我想將一些文本留在條上,並將一些值放在條的右側。 如果有人遇到過這個問題,請幫我在這裏添加文字。我會很快期待您的回覆。
在此先感謝
感謝您的建議。它運作良好。 – android 2011-01-17 05:07:14