Getting percentage value from seek bar?

Deadly 提交于 2019-12-10 11:22:42

问题


I have just like this figure, which is get value from this,

Here I Used SeekBar,but could not get value where i mention in figure. would you guys help me this problem?

So please also provide me information , what is the best solution to get this type of value?

Here all are differenet seek bar.

First SeekBar have 25% and second seek Baar 50%. If i have scroll seek bar then simultaneously increase or decrease the percentage in box.


回答1:


Create a view in xml

 <LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:weightSum="100" >

    <SeekBar
        android:id="@+id/SeekBarId"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="92" />

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:layout_marginLeft="4dp"
        android:layout_weight="8"
        android:gravity="center"/>
</LinearLayout>

set onSeekBarChageListener on the seekBar, like this:

seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener()
                    {

                        public void onStopTrackingTouch(SeekBar bar)
                        {
                            int value = bar.getProgress(); // the value of the seekBar progress
                        }

                        public void onStartTrackingTouch(SeekBar bar)
                        {

                        }

                        public void onProgressChanged(SeekBar bar,
                                int paramInt, boolean paramBoolean)
                        {
                            textView.setText("" + paramInt + "%"); // here in textView the percent will be shown
                        }
                    });



回答2:


String[] percent = { "0", "10", "20", "30", "40", "50", ... "100" };


seekbar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
            public void onStopTrackingTouch(SeekBar seekBar) {
            }

            public void onStartTrackingTouch(SeekBar seekBar) {
            }

            public void onProgressChanged(SeekBar seekBar, int progress,
                    boolean fromUser) {
                baths.setText("" + percent[progress] + "%");
            }
        });

Add do add in xml-layout in seekbar:-

android:max="10"


来源:https://stackoverflow.com/questions/9821614/getting-percentage-value-from-seek-bar

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!