动态地将一个圆圈在android系统 [英] Divide a circle dynamically in android
问题描述
我在Android应用程序的工作,我有刺的列表。如果串的列表中包含3串,我必须划分圆分成3等份和三个串中的圆的划分区域结合。我怎样才能做到这一点。哪个部件应该使用,使这个圈子。请HEL 点我。
I am working in an android application and I have a List of stings. If the List of string contains 3 string, I have to divide the circle into 3 equal parts and bind the three string in the divided area of the circle. How can I do this. Which widget should I use to make this circle. Please help me.
推荐答案
这只是一个样本。你需要根据自己的需要进行修改。既然你问了一个示例我已经粘贴下面code。
This is only a sample. You need to modify according to to your needs. Since you asked for a sample i have pasted the below code.
http://developer.android.com/training/custom-查看/自定义drawing.html 。文档在图纸上。有在链路
http://developer.android.com/training/custom-views/custom-drawing.html. Documentation on drawing. There is a sample at the end of the link
使用achartengine是容易的。 http://www.achartengine.org/
Using achartengine is easy. http://www.achartengine.org/
有关使用achartengine饼图。的http://wptrafficanalyzer.in/blog/android-drawing-pie-chart-using-achartengine/.
For pie chart using achartengine. http://wptrafficanalyzer.in/blog/android-drawing-pie-chart-using-achartengine/.
要吸取视图,你可以使用下面的示例。
To draw on view you can use the following sample.
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
MyView mv= new MyView(this);
setContentView(mv);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
class MyView extends View
{
Context c;
private Bitmap mBitmap;
private Canvas mCanvas;
private Path mPath;
private Paint mBitmapPaint;
private Paint mpaint,paint2;
public MyView(Context context) {
super(context);
c= context;
mpaint= new Paint();
mpaint.setColor(Color.RED);
mpaint.setStyle(Paint.Style.FILL);
paint2 = new Paint();
paint2.setColor(Color.GREEN);
paint2.setStrokeWidth(10);
mBitmapPaint = new Paint();
mBitmapPaint.setColor(Color.RED);
// TODO Auto-generated constructor stub
}
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
mBitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
mCanvas = new Canvas(mBitmap);
}
@Override
protected void onDraw(Canvas canvas) {
Display display = ( (Activity) c).getWindowManager().getDefaultDisplay();
float w = display.getWidth();
float h = display.getHeight();
canvas.drawCircle(w/2, h/2, 350, mpaint);
canvas.drawLine(w/2, h/2, 20, h/2, paint2);
}
}
}
您与canvas.drawText(文字,X,Y,油漆)绘制文本。请根据你的需求是一样的。在视图中添加动画。
You draw text with canvas.drawText(text, x, y, paint). Modify the same according to your needs. Add Animation on the view.
这篇关于动态地将一个圆圈在android系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!