<small id='vG312'></small><noframes id='vG312'>

    <legend id='vG312'><style id='vG312'><dir id='vG312'><q id='vG312'></q></dir></style></legend>
    • <bdo id='vG312'></bdo><ul id='vG312'></ul>

      <i id='vG312'><tr id='vG312'><dt id='vG312'><q id='vG312'><span id='vG312'><b id='vG312'><form id='vG312'><ins id='vG312'></ins><ul id='vG312'></ul><sub id='vG312'></sub></form><legend id='vG312'></legend><bdo id='vG312'><pre id='vG312'><center id='vG312'></center></pre></bdo></b><th id='vG312'></th></span></q></dt></tr></i><div id='vG312'><tfoot id='vG312'></tfoot><dl id='vG312'><fieldset id='vG312'></fieldset></dl></div>

      <tfoot id='vG312'></tfoot>

      修改 Android seekbar 小部件以垂直操作

      Modifying the Android seekbar widget to operate vertically(修改 Android seekbar 小部件以垂直操作)

    1. <small id='9g1az'></small><noframes id='9g1az'>

      <i id='9g1az'><tr id='9g1az'><dt id='9g1az'><q id='9g1az'><span id='9g1az'><b id='9g1az'><form id='9g1az'><ins id='9g1az'></ins><ul id='9g1az'></ul><sub id='9g1az'></sub></form><legend id='9g1az'></legend><bdo id='9g1az'><pre id='9g1az'><center id='9g1az'></center></pre></bdo></b><th id='9g1az'></th></span></q></dt></tr></i><div id='9g1az'><tfoot id='9g1az'></tfoot><dl id='9g1az'><fieldset id='9g1az'></fieldset></dl></div>
          <bdo id='9g1az'></bdo><ul id='9g1az'></ul>

        • <legend id='9g1az'><style id='9g1az'><dir id='9g1az'><q id='9g1az'></q></dir></style></legend>
              • <tfoot id='9g1az'></tfoot>
                  <tbody id='9g1az'></tbody>
                本文介绍了修改 Android seekbar 小部件以垂直操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我正在尝试让一个垂直搜索栏与模拟器一起使用,但我有点卡住了.我可以让搜索栏以我想要的方式显示,我可以得到进展来做我想做的事,我可以修改onTouchEvent 让拇指垂直而不是水平.我不能做的是让拇指移到外面默认为 29 个水平像素,不使用 setThumbOffset().这在本身不是问题.问题来自于我根本不理解 thumbOffset - 我猜.我想我可以(适当地)调整小部件,我很确定我做的不对.或者也许我可以如果我能弄清楚,只需使用 thumbOffset .既然我可以正确计算进度我以为我只会使用线性小部件的进度函数 * (getTop() - getBottom()) 但那似乎没有这样做.但我无法弄清楚偏移量是多少以周围为中心.

                I'm trying to get a vertical seekbar going with the emulator, but I'm sort of stuck. I can get the seekbar to display the way I want it to, and I can get the progress to do what I want, and I can modify the onTouchEvent to get the thumb to go vertically instead of horizontally. What I can't do is get the thumb to move outside of the default 29 horizontal pixels without using setThumbOffset(). This in itself isn't a problem. The problem is coming from the fact that I don't understand the thumbOffset at all -- I guess. I think I could (properly) resize the widget, which I am pretty sure I'm not doing right. Or maybe I could just use the thumbOffset if I could figure it out. Since I can calculate the progress correctly I thought I would just use a linear function of progress * (getTop() - getBottom()) of the widget but that doesn't seem to do it. But I can't figure out what the offset is centered around.

                顺便说一句,我真的不确定我在做什么onSizeChanged() 是理智的,或者如果它以后会咬我的屁股开.

                As a somewhat aside, I am really unsure if what I am doing in onSizeChanged() is sane or if it's going to bite me in the ass later on.

                这是 main.xml 布局:

                Here's the main.xml layout:

                <?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>
                

                还有类(忽略调试垃圾):

                And the class (ignore the debugging junk):

                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 = -1, yPos = -1;
                        private int top = -1, bottom = -1, left = -1, right = -1;
                
                        public SlideBar(Context context) {
                                super(context);
                        }
                        public SlideBar(Context context, AttributeSet attrs)
                        {
                                super(context, attrs);
                                oOffset = this.getThumbOffset();
                                oProgress = this.getProgress();
                        }
                        public SlideBar(Context context, AttributeSet attrs, int defStyle)
                        {
                                super(context, attrs, defStyle);
                        }
                
                        protected synchronized void onMeasure(int widthMeasureSpec, intheightMeasureSpec)
                        {
                                int height = View.MeasureSpec.getSize(heightMeasureSpec);
                                oHeight = height;
                                this.setMeasuredDimension(oWidth, oHeight);
                
                        }
                        protected void onSizeChanged(int w, int h, int oldw, int oldh)
                        {
                                super.onSizeChanged(h, w, oldw, oldh);
                        }
                        protected void onLayout(boolean changed, int l, int t, int r, int b)
                        {
                                super.onLayout(changed, l, t, r, b);
                                left = l;
                                right = r;
                                top = t;
                                bottom = b;
                        }
                        protected void onDraw(Canvas c)
                        {
                                c.rotate(90);
                                c.translate(0,-29);
                                super.onDraw(c);
                        }
                        public boolean onTouchEvent(MotionEvent event)
                        {
                                xPos = event.getX();
                                yPos = event.getY();
                                float progress = (yPos-this.getTop())/(this.getBottom()-this.getTop());
                                oOffset = this.getThumbOffset();
                                oProgress = this.getProgress();
                                Log.d("offset" + System.nanoTime(), new Integer(oOffset).toString());
                                Log.d("progress" + System.nanoTime(), new Integer(oProgress).toString());
                
                                float offset;
                
                                offset = progress * (this.getBottom()-this.getTop());
                
                                this.setThumbOffset((int)offset);
                
                                Log.d("offset_postsetprogress" + System.nanoTime(), new Integer(oOffset).toString());
                                Log.d("progress_postsetprogress" + System.nanoTime(), new Integer(oProgress).toString());
                
                                this.setProgress((int)(100*event.getY()/this.getBottom()));
                                return true;
                        }
                
                }
                

                推荐答案

                对于API 11 及更高版本,可以使用seekbar的XML属性(android:rotation="270") 用于垂直效果.

                For API 11 and later, can use seekbar's XML attributes(android:rotation="270") for vertical effect.

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

                对于较旧的 API 级别(前 API10),请使用:https://github.com/AndroSelva/Vertical-SeekBar-Android 或查看此处示例

                For older API level (ex API10),use: https://github.com/AndroSelva/Vertical-SeekBar-Android or see this sample here

                您还必须更新它的高度和Iftikhar 建议的宽度

                按顺序

                seekBar.setLayoutParams(
                                new ViewGroup.LayoutParams(convertDpToPixels(1.0f,mContext), ViewGroup.LayoutParams.WRAP_CONTENT));
                

                //没有测试过..

                在哪里

                public static int convertDpToPixels(float dp, Context context){
                    Resources resources = context.getResources();
                    return (int) TypedValue.applyDimension(
                            TypedValue.COMPLEX_UNIT_DIP,
                            dp, 
                            resources.getDisplayMetrics()
                    );
                }
                

                这篇关于修改 Android seekbar 小部件以垂直操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                How can I use CClistview in COCOS2d Android?(如何在 COCOS2d Android 中使用 CClistview?)
                cocos2d-android: how to display score(cocos2d-android:如何显示分数)
                Sqlite database not copied from asset folder Android(Sqlite 数据库未从资产文件夹 Android 复制)
                SQLite Database Copy Appears Corrupted When Generated by Device and not Emulator(SQLite 数据库副本在由设备而不是模拟器生成时出现损坏)
                Android file copy(安卓文件拷贝)
                Android how to detect Copy event of Edittext in android(Android如何在android中检测Edittext的Copy事件)

                  <bdo id='KgzVq'></bdo><ul id='KgzVq'></ul>
                    <tfoot id='KgzVq'></tfoot>
                    • <legend id='KgzVq'><style id='KgzVq'><dir id='KgzVq'><q id='KgzVq'></q></dir></style></legend>

                      1. <small id='KgzVq'></small><noframes id='KgzVq'>

                      2. <i id='KgzVq'><tr id='KgzVq'><dt id='KgzVq'><q id='KgzVq'><span id='KgzVq'><b id='KgzVq'><form id='KgzVq'><ins id='KgzVq'></ins><ul id='KgzVq'></ul><sub id='KgzVq'></sub></form><legend id='KgzVq'></legend><bdo id='KgzVq'><pre id='KgzVq'><center id='KgzVq'></center></pre></bdo></b><th id='KgzVq'></th></span></q></dt></tr></i><div id='KgzVq'><tfoot id='KgzVq'></tfoot><dl id='KgzVq'><fieldset id='KgzVq'></fieldset></dl></div>
                          <tbody id='KgzVq'></tbody>