gpt4 book ai didi

Android 垂直 Seekbar 拇指对齐不正确

转载 作者:行者123 更新时间:2023-11-29 15:49:10 25 4
gpt4 key购买 nike

我有一个带有垂直搜索栏的 LinearLayout。对于垂直搜索栏,我使用的是自定义类。使用 android:layout_weight="1" 搜索栏拇指对齐不正确。

verticalseekbar.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >

<com.example.verticalseekbardemo.VerticalSeekBar
android:id="@+id/seekBar1"
android:layout_width="0dp"
android:layout_height="200dp"
android:layout_weight="1"
android:progress="50" />

<com.example.verticalseekbardemo.VerticalSeekBar
android:id="@+id/seekBar2"
android:layout_width="0dp"
android:layout_height="200dp"
android:layout_weight="1"
android:progress="30" />

<com.example.verticalseekbardemo.VerticalSeekBar
android:id="@+id/seekBar3"
android:layout_width="0dp"
android:layout_height="200dp"
android:layout_weight="1"
android:progress="10" />

<com.example.verticalseekbardemo.VerticalSeekBar
android:id="@+id/seekBar4"
android:layout_width="0dp"
android:layout_height="200dp"
android:layout_weight="1" />

<com.example.verticalseekbardemo.VerticalSeekBar
android:id="@+id/seekBar5"
android:layout_width="0dp"
android:layout_height="200dp"
android:layout_weight="1"
android:progress="80" />

</LinearLayout>

VerticalSeekBar.java

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
public synchronized void setProgress(int progress) // it is necessary for
// calling setProgress
// on click of a button
{
super.setProgress(progress);
onSizeChanged(getWidth(), getHeight(), 0, 0);
}

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

Thumb is not aligned properly

有没有人遇到过这种问题。

谢谢。

最佳答案

我遇到了同样的问题。解决它的唯一方法是将每个搜索栏放入一个 FrameLayout 中,如下所示:

<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">

<com.example.verticalseekbardemo.VerticalSeekBar
android:id="@+id/seekBar1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:progress="50" />
</FrameLayout>

希望对你有帮助。

关于Android 垂直 Seekbar 拇指对齐不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31376661/

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