2012-11-01 6 views
0

나는 dimmer switch.i를 사용하여 조명을 제어하려는 응용 프로그램을 개발 중입니다.이 컨트롤을 사용하여 조명을 밝게하고 관련 값을 가져오고 싶습니다.android에 사용자 정의 seekbar를 만드는 방법

내 질문은 어떤 컨트롤이이 요구 사항에 적합할까요?

나는 약간의 연구를했고 Seekbar이 나의 요구를 만족시킬 수 있다는 것을 알게되었다. 그런데 어떻게 아래의 이미지처럼 seekbar 정의를 만들 수 있습니까? 이를 달성하기 위해 다른 방법이있는 경우

enter image description here

, 다음 좀 ideas.Any 제안을주고 지침을 주시면 감사하겠습니다.

답변

0

이 예제는 내 앱에서 실행 중이지만 requirment는 수정합니다.

package android.widget; 

import android.content.Context; 
import android.graphics.Canvas; 
import android.util.AttributeSet; 
import android.view.MotionEvent; 

public class VerticalSeekBar extends SeekBar { 

    public VerticalSeekBar(Context context) { 
     super(context); 
    } 

    public VerticalSeekBar(Context context, AttributeSet attrs, int defStyle) { 
     super(context, attrs, defStyle); 
    } 

    public VerticalSeekBar(Context context, AttributeSet attrs) { 
     super(context, attrs); 
    } 

    protected void onSizeChanged(int w, int h, int oldw, int oldh) { 
     super.onSizeChanged(h, w, oldh, oldw); 
    } 

    @Override 
    protected synchronized void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 
     super.onMeasure(heightMeasureSpec, widthMeasureSpec); 
     setMeasuredDimension(getMeasuredHeight(), getMeasuredWidth()); 
    } 

    protected void onDraw(Canvas c) { 
     c.rotate(-90); 
     c.translate(-getHeight(), 0); 

     super.onDraw(c); 
    } 

    @Override 
    public boolean onTouchEvent(MotionEvent event) { 
     if (!isEnabled()) { 
      return false; 
     } 

     switch (event.getAction()) { 
      case MotionEvent.ACTION_DOWN: 
      case MotionEvent.ACTION_MOVE: 
      case MotionEvent.ACTION_UP: 
       setProgress(getMax() - (int) (getMax() * event.getY()/getHeight())); 
       onSizeChanged(getWidth(), getHeight(), 0, 0); 
       break; 

      case MotionEvent.ACTION_CANCEL: 
       break; 
     } 
     return true; 
    } 
} 
+0

감사합니다. 다른 방법으로 연락 할 수 있습니까? – juned

+0

채팅 목록에 연결 – ckpatel

관련 문제