필자는 프로그램 적으로 그려지는 조각을 포함하는 클래스 (SpotDetails)를 가지고 있습니다. 지금까지는 조각 클래스 (WindRose)를 메인 클래스의 자식으로 사용했습니다.AsyncTask로 뷰 이동하기
더 나은 사용자 경험을 위해 WindRose 클래스를 AsynTask로 옮기고 싶습니다. 이제 응용 프로그램은 주 스레드에서 너무 많은 작업을 겪고 있습니다.
WindRose windRose = new WindRose(SpotDetails.this);
//Add a new windRose (Which is created under)
FrameLayout.addView(windRose);
풍배 코드 : 다음 풍배을 구현하는
코드 내가 일이 :)
I 불분명 한 경우에는 바로 그렇게 말씀 해주십시오 가지를 설명하면
public class WindRose extends View {
public WindRose(Context context) {
super(context);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
float height = (float) getHeight();
float width = (float) getWidth();
float radius;
if (width > height) {
radius = height/2;
} else {
radius = width/2;
}
// radius = (height)/ 2;
Path path = new Path();
path.addCircle(width, height, radius, Path.Direction.CCW);
///2
Resources resources = getResources();
int color = resources.getColor(R.color.green_back);
Paint paint = new Paint();
paint.setColor(color);
paint.setStrokeWidth(5);
paint.setStyle(Paint.Style.FILL);
float center_x, center_y;
center_x = width/2;
center_y = height/2;
final RectF oval = new RectF();
//Formulas :
//SD = Start Degree
//ED = End Degree
//If cakepiece passes 0 (East)
//SD, 360-(SD+ED)
//Else :
//SD, (ED-SD)
oval.set(center_x - radius, center_y - radius, center_x + radius, center_y + radius);
if (End > Start) {
canvas.drawArc(oval, Start, (End - Start), true, paint);
} else if (End < Start) {
canvas.drawArc(oval, Start, ((360 - Start) + End), true, paint);
}
}
}
임 확실하지 이렇게하려고했습니다 :
public class WindRose extends Activity {
float Start, End;
Context context;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
public View DrawRose (Context context){
this.context = context;
WindRoseDrawer windRoseDrawer = new WindRoseDrawer(context);
return null; //What should i return here ?
}
private class DrawWindRose extends AsyncTask<String, Void, Void> {
@Override
protected void onPreExecute() {
super.onPreExecute();
}
@Override
protected Void doInBackground(String... strings) {
return null;
}
@Override
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
}
}
public class WindRoseDrawer extends View {
public WindRoseDrawer(Context context) {
super(context);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
float height = (float) getHeight();
float width = (float) getWidth();
float radius;
if (width > height) {
radius = height/2;
} else {
radius = width/2;
}
// radius = (height)/ 2;
Path path = new Path();
path.addCircle(width, height, radius, Path.Direction.CCW);
///2
Resources resources = getResources();
int color = resources.getColor(R.color.green_back);
Paint paint = new Paint();
paint.setColor(color);
paint.setStrokeWidth(5);
paint.setStyle(Paint.Style.FILL);
float center_x, center_y;
center_x = width/2;
center_y = height/2;
final RectF oval = new RectF();
//Formulas :
//SD = Start Degree
//ED = End Degree
//If cakepiece passes 0 (East)
//SD, 360-(SD+ED)
//Else :
//SD, (ED-SD)
oval.set(center_x - radius, center_y - radius, center_x + radius, center_y + radius);
if (End > Start) {
canvas.drawArc(oval, Start, (End - Start), true, paint);
} else if (End < Start) {
canvas.drawArc(oval, Start, ((360 - Start) + End), true, paint);
}
}
}
}
하지만 SpotDetails에 어떻게 다시 구현해야합니까? 그리고 DrawRose에서 무엇을 반환해야합니까?
의 당신은 내가 당신의 평균 바로 당신이 AsynkTask''의 constructor''에 그것을 전달하거나 내가 추가 한 – Raghunandan
을 AsyncTask를 위해 이동보기로 뜻 불분명 문제를 해결하려는 나의 시도? 그게 당신이 의미 한 것입니까? 결국 메인 클래스에서 이것을 어떻게 구현해야합니까? –
doInBackground' 방법 '에 매개 변수로 전달할 수 있습니다 얻을 경우 – Dukes