gpt4 book ai didi

Android Vertical Seek Bar 像 Google Play Music App

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:24:19 24 4
gpt4 key购买 nike

我想要像下图那样的 Vertical seekBar (for android 4.O+))。它在 Google Play Music应用。

enter image description here

我试过下面的方法:但是我不能设置高度和宽度

<SeekBar 
android:id="@+id/seekBar1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:rotation="270"
/>

我想要如下:

enter image description here

现在我用过这个Stack Answer但是管理多个垂直搜索栏太难了。

我正在寻找比这更好的方法。


编辑:

我使用了以下来自 iDroid Explorer's answer 的代码尝试显示垂直搜索栏:

private void setupEqualizerFxAndUI() {

for (short i = 0; i < 5; i++) {

LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT);
layoutParams.weight = 3;

LinearLayout row = new LinearLayout(this);
row.setOrientation(LinearLayout.VERTICAL);
row.setLayoutParams(layoutParams);

TextView minDbTextView = new TextView(this);
minDbTextView.setLayoutParams(new ViewGroup.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT));
minDbTextView.setText(i + " dB");

TextView maxDbTextView = new TextView(this);
maxDbTextView.setLayoutParams(new ViewGroup.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT));
maxDbTextView.setText(i + " dB");

LinearLayout.LayoutParams layoutParams1 = new LinearLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
layoutParams1.weight = 2;

SeekBar bar = new SeekBar(this);
bar.setLayoutParams(layoutParams1);
bar.setMax(100);
bar.setProgress(20);
bar.setRotation(270);
bar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {

}

public void onStartTrackingTouch(SeekBar seekBar) {
}

public void onStopTrackingTouch(SeekBar seekBar) {
}
});

row.addView(minDbTextView);
row.addView(bar);
row.addView(maxDbTextView);

mLinearLayout.addView(row);

}
}

但它看起来像下面:指标没有显示。

enter image description here

如果我只使用一个 seekBar,那么它看起来像下面这样:

enter image description here

它就像在布局文件中使用:android:rotation="270"

最佳答案

iDroid Explorer 的代码很棒,对我完成工作有很大帮助,但它缺少一些部分。这是我的破解版,它对我很有用,我希望它也适合你。

public class VerticalSeekBar extends SeekBar {

protected OnSeekBarChangeListener changeListener;
protected int x, y, z, w;

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);
}

@Override
protected synchronized 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 void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(heightMeasureSpec, widthMeasureSpec);
setMeasuredDimension(getMeasuredHeight(), getMeasuredWidth());
}

@Override
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);
if (changeListener != null) changeListener.onStartTrackingTouch(this);
break;
case MotionEvent.ACTION_UP:
setSelected(false);
setPressed(false);
if (changeListener != null) changeListener.onStopTrackingTouch(this);
break;
case MotionEvent.ACTION_MOVE:
int progress = getMax() - (int) (getMax() * event.getY() / getHeight());
setProgress(progress);
onSizeChanged(getWidth(), getHeight(), 0, 0);
if (changeListener != null) changeListener.onProgressChanged(this, progress, true);
break;

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

@Override
public synchronized void setOnSeekBarChangeListener(OnSeekBarChangeListener listener) {
changeListener = listener;
}

@Override
public synchronized void setProgress(int progress) {
if (progress >= 0)
super.setProgress(progress);

else
super.setProgress(0);
onSizeChanged(x, y, z, w);
if (changeListener != null) changeListener.onProgressChanged(this, progress, false);
}
}

关于Android Vertical Seek Bar 像 Google Play Music App,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18395064/

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