gpt4 book ai didi

Android 6.0 Marshmallow 停止显示 Vertical SeekBar 缩略图

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

我一直在使用 this basic wrapper在 SeekBar 周围,但发现它隐藏了拇指,或者做了一些时髦的事情,比如在棉花糖下面让它在白色背景上变成白色。

我使用 AS "BlankActivity"向导创建了一个项目来说明这一点,除了这里描述的内容之外,没有改变默认值。左边是 Lollipop,同样的代码在 Marshmallow 的右边运行:

enter image description here

有一个自定义的水平 SeekBar 来测试自定义它们是否存在一般问题,但事实并非如此。左侧的第一个垂直样式没有样式,这在 Marshmallow 之前很好,但不是,中央样式明确使用 Widget.Material.Light.SeekBar 样式来测试默认值是否未被拾取,并且最后一个提供了一个很大的线索,因为它使用了旧的 Widget.Holo.SeekBar 样式,然后它出现了,尽管看起来像是几年前出现的。

这是为此的布局:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MainActivity"
>

<com.otamate.seekbarmarshbug.CustomSeekBar
android:id="@+id/seekBarCustom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>

<com.otamate.seekbarmarshbug.VerticalSeekBar
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_below="@+id/seekBarCustom"
/>

<com.otamate.seekbarmarshbug.VerticalSeekBar
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:layout_below="@+id/seekBarCustom"
android:layout_centerHorizontal="true"
style="@android:style/Widget.Material.Light.SeekBar"
/>

<com.otamate.seekbarmarshbug.VerticalSeekBar
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:layout_below="@+id/seekBarCustom"
style="@android:style/Widget.Holo.SeekBar"
/>

</RelativeLayout>

CustomSeekBar:

package com.otamate.seekbarmarshbug;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.SeekBar;

public class CustomSeekBar extends SeekBar {

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

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

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

和 VerticalSeekBar:

package com.otamate.seekbarmarshbug;

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

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

}

最佳答案

试试这段代码。效果很好!

<seekBar>
.....
android:splitTrack="false"
</seekBar>

关于Android 6.0 Marshmallow 停止显示 Vertical SeekBar 缩略图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33112277/

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