寻求酒吧进度无法正常显示

时间:2013-10-29 10:48:45

标签: android seekbar

我设置了搜索栏的属性。它达到一个过程,但其过程未达到1,如下图所示

enter image description here

 sbpassangers.setProgress(1); //set this at onCreate

xml:

<SeekBar
      android:id="@+id/sBpassangers"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:layout_alignParentTop="true"
      android:layout_toLeftOf="@+id/tvPassengers"
      android:layout_toRightOf="@+id/ivPhone"
      android:layout_weight="2"
      android:paddingBottom="3dp"
      android:paddingLeft="2dp"
      android:paddingTop="3dp" />

java代码:

sbpassangers.setProgress(1);
    sbpassangers.setMax(sb1.getProgress());
    tvtaxipassangers.setText(Integer.toString(1));
    //sb1.setMax(9);
    //sb1.setProgress(2); // Set it to zero so it will start at the left-most edge
    sbpassangers.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {

        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            seekBar.setProgress(progress);
         if(progress == 0){
             seekBar.setProgress(1);
         }
            tvtaxipassangers.setText(Integer.toString(seekBar.getProgress()));

        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {}

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {}

    });

应该是这样的:

enter image description here

请帮助解决这个问题

3 个答案:

答案 0 :(得分:6)

交换两行

    sbpassangers.setProgress(1);
    sbpassangers.setMax(sb1.getProgress());

sbpassangers.setMax(sb1.getProgress());
sbpassangers.setProgress(1);

除非您定义进度可以采用的最大值,否则无法设置搜索条的进度。

答案 1 :(得分:1)

seekBar是我们在自定义应用程序中使用的必备组件。

请制作一个演示项目并按照以下代码添加到MainActivity

<强> SeekbarActivity.java

package com.example.seekbarwidget;


import android.app.Activity;
import android.os.Bundle;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView;

public class SeekbarActivity extends Activity { 
 TextView textview; 
 SeekBar seekbar;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_seekbar); 

        textview = (TextView)findViewById(R.id.textView);
        seekbar = (SeekBar)findViewById(R.id.seekBar1);
        seekbar.setMax(10);
        seekbar.setProgress(5);
        //initControls();

        seekbar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) { 
           //add here your implementation 
            } 
            @Override
            public void onStartTrackingTouch(SeekBar seekBar) { 
              //add here your implementation
            } 
            @Override
            public void onProgressChanged(SeekBar seekBar, int progress,
                boolean fromUser) { 

             textview.setText(" value = " +Integer.toString(progress));
            }
          });
    }

}


the activity_seekbar.xml is having following layout

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:orientation="vertical" >

    <SeekBar
        android:id="@+id/seekBar1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="15dp"
        android:layout_marginTop="125dp"
        android:indeterminate="false"
        android:max="10"
        android:paddingLeft="15dp"
        android:paddingRight="15dp"
        android:progress="5"
        android:progressDrawable="@drawable/styled_progress"
        android:secondaryProgress="5"
        android:thumb="@drawable/thumbler_small" />

    <TextView
        android:id="@+id/textView"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="Show seekbar value"
        android:textColor="#CD2134"
        android:textSize="27px"
        android:textStyle="bold" />

</LinearLayout>

finally the  styled_progress.xml inside drawable folder is having the lines

<?xml version="1.0" encoding="UTF-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >

    <item
        android:id="@+android:id/SecondaryProgress"
        android:drawable="@drawable/progress_cyan"/>
    <item
        android:id="@+android:id/progress"
        android:drawable="@drawable/progress_red"/>

</layer-list>

Custom Seek Bar

答案 2 :(得分:0)

要获得确切答案,您必须提供更多信息。我猜测你需要设置最大值,

setMax(int)

http://developer.android.com/reference/android/widget/ProgressBar.html

的更多信息