【问题标题】:Seekbar increase value upto 100搜索栏增加值高达 100
【发布时间】:2013-01-31 07:58:25
【问题描述】:

我有一个 max=25 的搜索栏。我想要做的是当用户将搜索栏拖到最大值并且它处于按下状态时,而不是在达到最大值后搜索栏仍然连续递增,即 26、27、28、.... 100。(如果按下搜索栏)

我尝试了两种使用循环和线程的方法,但它们都不起作用。

我有一个显示进度值的文本视图,

这里是代码。

public void onProgressChanged(SeekBar seekBar, int progress,
            boolean fromUser) {
         float p_prog = (float) (progress/10.0);
        // TODO Auto-generated method stub
        switch (seekBar.getId()) {
        case R.id.seekbar_bar:

            fat_count = p_prog;
            if (p_prog == 0) {

                txt_Fat.setBackgroundDrawable(res
                        .getDrawable(R.drawable.fat_at_null));
                txt_Fat.setText(p_prog + "g   ");

                first_plus.setVisibility(View.GONE);
                first_plus.setAnimation(null);
            } else if (p_prog > 0 && p_prog < 3) {
                txt_Fat.setBackgroundDrawable(res
                        .getDrawable(R.drawable.fat_green));
                txt_bottom_description.setText("Fat started");
                txt_Fat.setText(p_prog + "g   ");

            } else if (p_prog > 3 && p_prog < 20) {
                txt_Fat.setBackgroundDrawable(res
                        .getDrawable(R.drawable.fat_yellow));
                first_plus.setAnimation(null);
                first_plus.setVisibility(View.GONE);
                txt_Fat.setText(p_prog + "g   ");

            } else if (p_prog >= 20) {

                txt_Fat.setBackgroundDrawable(res
                        .getDrawable(R.drawable.fat_red));
                first_plus.setVisibility(1);
                first_plus.startAnimation(anim);
                txt_Fat.setText(p_prog+"g   ");

                if(s_Fat.isPressed() && p_prog >24){
                    for(float z=p_prog; z<100;z++){
                        txt_Fat.setText(z+"g   ");
                    }
                }


            }

【问题讨论】:

    标签: android android-intent android-widget seekbar


    【解决方案1】:

    需要使用xml属性android:maxlike

    <SeekBar android:id="@+id/seekbartest"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:max="25"/>
    

    参考文档here

    【讨论】:

    • 我已经设置了这个值。我想在达到最大值 25 后增加该值。并且搜索栏像我一样处于按下状态.. if(s_Fat.isPressed() && p_prog >24)
    • 是的,我没有超过 25 。当它达到最大值(25)时,我想增加/增加它到 100 并且当它处于按下状态时。
    • 那你为什么定义最大值为25??还有你是如何确定按下状态的??
    • 我定义它是因为当用户移动搜索栏并达到 20 时,如果进度大于 20,则 textview 的背景将变为红色。当它达到 25 时,它应该继续增加文本视图中的值。这向用户显示搜索栏已达到最大值,但该值不断增加
    • 你是如何确定按下状态的?你在捕捉 seekbar 的 onClick 吗?如果是这样,您可以将检查移动到 onClick 本身。
    猜你喜欢
    • 1970-01-01
    • 2017-01-16
    • 2015-07-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-29
    • 1970-01-01
    相关资源
    最近更新 更多