我已经实现了共同指向的VerticalSeekBar张贴在这里.事实上,SeekBar的运作有点古怪.以下是我onTouchEvent()对该示例的略微改编:
public boolean onTouchEvent(MotionEvent event)
{
xPos = event.getX();
yPos = event.getY();
oOffset = this.getThumbOffset();
oProgress = this.getProgress();
//Code from example - Not working
//this.setThumbOffset( progress * (this.getBottom()-this.getTop()) );
this.setProgress((int)(29*yPos/this.getBottom()));
return true;
}
Run Code Online (Sandbox Code Playgroud)
我已经设法实现了一个VerticalSeekBar,其中进度按预期更新并且功能齐全,但拇指并没有效仿.这只是一个图形故障,所以我现在忽略它.但是,让它工作会很好.这个SeekBar有max = 20.
但是,我尝试用另一个VerticalSeekBar实现max = 1000.显然,它使用相同的代码,因此您将采用相同的行为.即使我的手指滑过SeekBar并最终离开屏幕,我也只能达到0~35的进度.如果我只是在进度条的末尾(应该是progress ~ 900)附近点击它会返回大约35的进度,黄色进度条通过保持靠近顶部来反映该值.
我的问题是:有没有人有一个工作垂直SeekBar的链接,或知道如何适应这个特定的例子?
我正在使用一个drawable for seekbar thumb with
android:thumb="@drawable/thumb"
Run Code Online (Sandbox Code Playgroud)
如何在倾角单元中设置此拇指的大小?因为我使用了类似于搜索栏的样式
<style name="CustomSeekBar">
<item name="android:indeterminateOnly">false</item>
<item name="android:minHeight">8dip</item>
<item name="android:maxHeight">8dip</item>
<item name="android:thumbOffset">8dip</item>
</style>
Run Code Online (Sandbox Code Playgroud)
我想要拇指的12dip高度和宽度.
我想实现一个滑块,它基本上是两条线,一条垂直线和一条水平线,穿过触摸屏幕的地方.我设法做了一个,但我必须提出问题:
这是代码:
public class Slider extends View {
private Controller controller = new Controller();
private boolean initialisedSlider;
private int sliderWidth, sliderHeight;
private Point pointStart;
private Paint white;
private int mode;
final static int VERTICAL = 0, HORIZONTAL = 1, BOTH = 2;
public Slider(Context context) {
super(context);
setFocusable(true);
// TODO Auto-generated constructor stub
}
public Slider(Context context, AttributeSet attrs) {
super(context, attrs);
setFocusable(true);
pointStart = new Point();
initialisedSlider = false;
mode = Slider.BOTH;
}
@Override
protected void onDraw(Canvas …Run Code Online (Sandbox Code Playgroud) 我试图让一个垂直的搜索栏与模拟器一起运行,但我有点卡住了.我可以让搜索栏显示我想要的方式,我可以获得进展以做我想要的,我可以修改onTouchEvent以使拇指垂直而不是水平移动.我不能做的是让拇指移动到默认的29个水平像素之外而不使用setThumbOffset().这本身不是问题.问题来自于我根本不理解thumbOffset这一事实 - 我猜.我想我可以(正确地)调整小部件的大小,我很确定我做得不对.或者也许我可以使用thumbOffset,如果我能搞清楚的话.由于我可以正确地计算进度,我以为我只会使用小部件的进度*(getTop() - getBottom())的线性函数,但似乎没有这样做.但我无法弄清楚偏移的中心位置.
在某种程度上,我真的不确定我在onSizeChanged()中所做的事情是否理智,或者是否会在以后咬我的屁股.
这是main.xml布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<com.mobilsemantic.mobipoll.SlideBar
android:id="@+id/slide"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:max="100"
android:progress="0"
android:secondaryProgress="25" />
<Button android:id="@+id/button"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="Hello, I am a Button" />
<TextView android:id="@+id/tracking"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
和类(忽略调试垃圾):
import android.content.Context;
import android.graphics.Canvas;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.widget.SeekBar;
public class SlideBar extends SeekBar {
private int oHeight = 320, oWidth = 29;
private int oProgress = -1, oOffset = -1;;
private float xPos …Run Code Online (Sandbox Code Playgroud) 我想垂直seekBar像下面的图像(对于Android 4.O +)).它在Google Play音乐应用中.

我尝试过以下方式:但我不能设置高度和宽度
<SeekBar
android:id="@+id/seekBar1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:rotation="270"
/>
Run Code Online (Sandbox Code Playgroud)
我想要如下:

现在我已经使用了这个Stack Answer,但它很难管理多个垂直搜索栏.
我正在寻找比这更好的方法.
编辑:
我使用了以下代码来自iDroid Explorer的答案尝试显示垂直搜索栏:
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)); …Run Code Online (Sandbox Code Playgroud) 我一直在SeekBar周围使用这个基本的包装,但发现它隐藏了拇指,或做了一些时髦的东西,比如在白色背景上使它变成白色,在Marshmallow下面.
我使用AS"BlankActivity"向导来创建一个项目来说明这一点,除了默认设置之外什么都没有改变.左边是Lollipop,同样的代码在Marshmallow右边运行:
有一个自定义水平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>
Run Code Online (Sandbox Code Playgroud)
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 …Run Code Online (Sandbox Code Playgroud) 搜寻未进行。所有seekbar变为零,但textView正确显示了值。
choosePreset.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View arg0)
{
LayoutInflater inflater = ((LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE));
View customView = inflater.inflate(R.layout.preset_list, null, false);
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setView(customView);
final String[] arr= getEqualizerPresets();
ArrayAdapter<String> namesAA= new ArrayAdapter<String> ( context,R.layout.myitemlist,arr );
ListView list = (ListView) customView.findViewById(R.id.mylist);
list.setAdapter(namesAA);
final AlertDialog ad = builder.create();
list.setOnItemClickListener(new OnItemClickListener()
{
public void onItemClick(AdapterView<?> parent, View view, final int position, long id)
{
Toast.makeText(context, "Position"+position, Toast.LENGTH_LONG).show();
//equalizerWrapper.usePreset((short)arr[position]);
for(int v=0;v<eqSeeks.length;v++)
{
// equalizerSeeks(v, eqSeeks[v]);
final int z = v;
eqSeeks[v].post(new …Run Code Online (Sandbox Code Playgroud) 我发现SeekBar有问题。在具有Android 4,5,6的设备上,我没有这样的问题,但是在具有Android 7的Samsung S8上,出现了进度条问题。如果删除旋转参数,则SeekBar变为水平,问题消失,但是我需要标准的垂直SeekBar。 更新:Nexus模拟器API 24(Android 7)上的相同问题。我已附加了我在Android 6(LG,Sony)和Android 7(Samsung S8)上运行的应用程序的2个屏幕截图和代码:
<SeekBar android:id="@+id/seekBar"
android:layout_width="100dp"
android:layout_height="42dp"
android:background="#20FFFFFF"
android:rotation="270"
android:layout_gravity="center"
>
</SeekBar>
Run Code Online (Sandbox Code Playgroud)
和完整的代码:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:id="@+id/icon"
android:layout_width="42dp"
android:layout_height="24dp"
android:paddingTop="6dp"
android:background="#20FFFFFF"
android:layout_gravity="center"
android:src="@drawable/iconvolume" />
<LinearLayout
android:layout_width="42dp"
android:layout_height="100dp"
android:gravity="center">
<SeekBar android:id="@+id/seekBar"
android:layout_width="100dp"
android:layout_height="42dp"
android:background="#20FFFFFF"
android:rotation="270"
android:layout_gravity="center"
>
</SeekBar>
</LinearLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)