如何在号码选择器中隐藏上一个和下一个号码? [英] How to hide the previous and next numbers in a number picker?

查看:164
本文介绍了如何在号码选择器中隐藏上一个和下一个号码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

摘要

我正在尝试在Android数字选择器中隐藏上一个和下一个数字.此外,我正在扩展NumberPicker类,以便可以更改字体大小和颜色.我注意到我可能会更改值:

I'm attempting to hide the previous and next numbers in an Android number picker. Additionally, I'm extending the NumberPicker class so that I can change the font size and color. I've noticed that I could potentially change the value:

private static final int MODIFIED_SELECTOR_WHEEL_ITEM_COUNT = 3;

我只是不确定如何覆盖静态最终值.

I'm just not sure how I could override a static final value.

默认号码选择器:

所需的修改号码选择器 我希望使数字选择器看起来像这样,并保持动画完好:

Desired Modified Number Picker I would like to make the number picker look like so, with the animation in tact:

扩展号码选择器类别:

public class CustomStatNumberPicker extends android.widget.NumberPicker{
    private static final int MODIFIED_SELECTOR_WHEEL_ITEM_COUNT = 1;

    public CustomStatNumberPicker(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    public void addView(View child) {
        super.addView(child);
        updateView(child);
    }

    @Override
    public void addView(View child, int index, android.view.ViewGroup.LayoutParams params) {
        super.addView(child, index, params);
        updateView(child);
    }

    @Override
    public void addView(View child, android.view.ViewGroup.LayoutParams params) {
        super.addView(child, params);
        updateView(child);
    }

    private void updateView(View view) {
        if(view instanceof EditText){
            ((EditText) view).setTextSize(40);
            ((EditText) view).setTextColor(Color.parseColor("#FFFFFF"));
        }
    }

}

TL; DR;如何隐藏上一个和下一个数字选择器的值?要么通过覆盖方法,要么像我已经完成的那样修改扩展类.

TL;DR; How do I hide the previous and next number picker values? Either through overriding a method, or modifying the extended class like I've already done.

谢谢.

推荐答案

您可以修改绘图例程以跳过不在中心行中的任何索引.尝试在中更改条件1478行.

you could modify the drawing routine to skip over any index that isn't in the center row. Try changing the conditions at line 1478.

这篇关于如何在号码选择器中隐藏上一个和下一个号码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆