마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

룰렛을 만들고 있습니다 ㅜㅜ

0 추천
룰렛의 판 수는 최소 4개부터 최대 12개까지구요

 

에디터 박스에 어떠한 글자를 입력하면 롤렛의 판에 그 글자가 나타나게끔 하고 싶습니다

 

개발현황은 먼저 룰렛의 판 수를 고르면(4개면 4개, 5개면 5개)

 

그 수에 맞게 에티터 박스 수가 나오게끔 만들었으며

 

애니메이션을 이용하여 버튼을 누르면 그림이 회전하다가 천첞히 멈추는 것까지 하였습니다

(회전을 멈추는 각도도 랜덤하게 멈추게끔 만들었구요)

 

이제 개발하려는 것이 4개~12개까지의 룰렛의 이미지를 미리 만들어서

 

스위치케이스문을 이용하여 4개를 고르면 4개의 판을 나누어진 룰렛이

 

5개를 고르면 5개의 판으로 나누어진 룰렛이 나오게끔 하려고 하는데

 

여기서 글자를 이미지 위에 어떻게 나타나게 해야하는지를 감이 안 잡힙니다

 

어떤 식으로 해야할까요?
깡통로이드 (390 포인트) 님이 2014년 3월 25일 질문
Bitmap 과 canvas를 적절히 활용하면 될꺼같습니다.

2개의 답변

+1 추천

룰렛 보드를 하나 만들었습니다. 이미지뷰를 상속하는 커스텀 뷰로요.

 


public class RouletteBoard extends ImageView {
	private static final String TAG = RouletteBoard.class.getSimpleName();

	/**
	 * 그려지는 텍스트 없을경우 default
	 */
	private static final String DEFAULT_TEXT = "N/A";
	private String mText = "";

	/**
	 * 페인트 : 색 등을 지정하는
	 */
	private Paint mPaint = new Paint();
	
	private Context mContext = null;

	public RouletteBoard(Context context) {
		super(context);
		mContext = context;
	}

	public RouletteBoard(Context context, AttributeSet attrs) {
		super(context, attrs);
		mContext = context;
		init(attrs);
	}

	public RouletteBoard(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		mContext = context;
		init(attrs);
	}

	private void init(AttributeSet attrs) {
		mPaint = new Paint();
		mPaint.setColor(Color.BLACK);
		mPaint.setTextSize(20);
		mPaint.setStyle(Style.FILL);
		TypedArray a = mContext.getTheme().obtainStyledAttributes(
				attrs,
				R.styleable.RouletteBoard,
				0, 0);

		try {
			mText = a.getString(R.styleable.RouletteBoard_text);
			mText = (mText == null)? DEFAULT_TEXT : mText; // 체크하기
		} finally {
			a.recycle();
		}
		// TODO 색깔 등도 attrs 에 지정 해주면 좋죠.	
	}
	
	public void setText(String text) {
		mText = text;
	}
	
	public String getText() {
		return mText;
	}

	@Override
	protected void onDraw(Canvas canvas) {
		super.onDraw(canvas);
		int width = this.getWidth()/2;
		int height = this.getHeight()/2;
		width -= mPaint.measureText(mText)/2;
		canvas.drawText(mText, width, height, mPaint);
	}



}

 

그리고 

res/values/attrs.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
   <declare-styleable name="RouletteBoard">
       <attr name="text" format="reference|string" />
   </declare-styleable>
</resources>

그리고 메인 레이아웃 파일입니다.

custom 부분이랑 패키지 부분은 알아서 바꿔주세요~

text 를 xml 에서 넣을 수도 있고

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:custom="http://schemas.android.com/apk/res/com.example.tester"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <com.example.tester.RouletteBoard
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_launcher"
        custom:text="HIHIHI" />

</LinearLayout>

 

AndroidDictator (1,660 포인트) 님이 2014년 3월 27일 답변
+1 추천
오픈 소스 중 https://github.com/anupcowkur/Android-Wheel-Menu 를 참조 해보세요.
사악미소 (65,330 포인트) 님이 2014년 3월 27일 답변
...