gpt4 book ai didi

Android:垂直RatingBar?

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:56:22 27 4
gpt4 key购买 nike

如何旋转 RatingBar?是否有垂直自定义 RatingBar 的示例?

最佳答案

这是垂直评级栏的示例代码...

public class VerticalRatingBar extends RatingBar {
private int x, y, z, w;

@Override
protected void drawableStateChanged() {
// TODO Auto-generated method stub
super.drawableStateChanged();
}

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

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

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

protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(h, w, oldh, oldw);
this.x = w;
this.y = h;
this.z = oldw;
this.w = oldh;
}

@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:

setSelected(true);
setPressed(true);
break;
case MotionEvent.ACTION_MOVE:
setProgress(getMax()
- (int) (getMax() * event.getY() / getHeight()));
onSizeChanged(getWidth(), getHeight(), 0, 0);

break;
case MotionEvent.ACTION_UP:
setSelected(false);
setPressed(false);
break;

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

@Override
public synchronized void setProgress(int progress) {

if (progress >= 0)
super.setProgress(progress);

else
super.setProgress(0);
onSizeChanged(x, y, z, w);

}
}

关于Android:垂直RatingBar?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5581154/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com