你好,我正在嘗試爲我的應用製作一個均衡器,但我無法弄清楚如何製作按鈕。我真的不知道該如何解釋自己,所以這裏是揭示比我的話更圖片: 如何在android中製作可滾動按鈕
我是否需要動畫?你們能否指引我朝着正確的方向發展?
在此先感謝。
你好,我正在嘗試爲我的應用製作一個均衡器,但我無法弄清楚如何製作按鈕。我真的不知道該如何解釋自己,所以這裏是揭示比我的話更圖片: 如何在android中製作可滾動按鈕
我是否需要動畫?你們能否指引我朝着正確的方向發展?
在此先感謝。
我認爲你的意思是SeekBar。這是Android的JSlider。
正是我在找的東西。非常感謝 – madcoderz 2011-05-16 19:27:08
@Ted我發現[This older](http://stackoverflow.com/questions/631238/modifying-the-android-seekbar-widget-to-operate-vertically)主題具有相同的問題。 – 2011-05-16 19:50:38
是的,該線程上的建議還需要一個自定義小部件。我認爲這會比嘗試子類化SeekBar並強制它垂直操作要容易得多。 – 2011-05-16 19:59:11
這是簡單的垂直搜索欄....
public class SimpleVerticalSeekBar extends SeekBar {
public SimpleVerticalSeekBar(Context context) {
super(context);
}
public SimpleVerticalSeekBar(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public SimpleVerticalSeekBar(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;
}
}
在我看來,你需要創建擴展的ImageButton或imageview的按鈕自定義視圖和處理觸摸事件。這是第一個新手想法。 – 2011-05-16 19:12:31
@Madcoderz:我想在我的應用程序中創建一個音樂均衡器。可以幫助我。 – AB1209 2013-06-12 17:51:54