简体   繁体   English

在同一活动中使用2个搜索栏

[英]using 2 seekbars in the same activity

I have 2 seekbars A and B and i have 2 textviews C and D. A edits the value of C when moved and B edits the value of D when moved. 我有2个搜索栏A和B,我有2个文本视图C和D。A在移动时编辑C的值,B在移动时编辑D的值。 My code works fine. 我的代码工作正常。 However I want it so that when the user is using A then seekbar B becomes disabled and likewise when seekbar B is being used by the user A becomes disabled. 但是我想要它,以便当用户使用A时,搜索栏B会被禁用,同样,当用户A使用搜索栏B时,也会被禁用。 The way the seekbars become undisabled is when a user clicks on it to use it again. 搜索栏变为禁用状态的方式是用户单击它以再次使用它。 So if i were using seekbar A then B would be disabled then if i touched seekbar B it would be enabled and then A would be disabled. 因此,如果我使用搜索栏A,则将禁用B,然后如果我触摸搜索栏B,则将启用它,然后将A禁用。 Or even if it ment changing the seekbars colour which is blue at the moment to a light grey colour to give the illusion that it is disabled would be another way perhaps. 或者,即使将此时为蓝色的搜索杆颜色更改为浅灰色,以给出禁用它的错觉,也可能是另一种方式。 Neway i tried this. 纽威我尝试了这个。 for seekbar A 搜寻杆A

        @Override
        public void onStartTrackingTouch(SeekBar seekbar) {
            // TODO Auto-generated method stub

             seekbarB.setEnabled(false);
             seekbarA.setEnabled(true);
        }
        @Override
        public void onStopTrackingTouch(SeekBar seekbar) {
            // TODO Auto-generated method stub
             seekbarB.setEnabled(true);
             seekbarA.setEnabled(true);
        }

and for seekbar B 对于搜索栏B

@Override
        public void onStartTrackingTouch(SeekBar seekbar) {
            // TODO Auto-generated method stub
             seekbarB.setEnabled(true);
             //seekbarA.setEnabled(false);

        }
        @Override
        public void onStopTrackingTouch(SeekBar seekbar) {
            // TODO Auto-generated method stub
             seekbarB.setEnabled(true);
             seekbarA.setEnabled(true);
        }

but however this kind of worked but then when the user stopped using either of the seekbars the one that had been disabled became enabled again which I didnt want unless the user touched it. 但是这种工作有效,但是随后当用户停止使用两个搜索栏时,被禁用的搜索栏又重新启用了,除非用户不触摸,否则我不希望这样做。 Now i know what your thinking dont set the seekbars to enabled in the onstoptrackingtouch. 现在,我知道您的想法没有将onstoptrackingtouch中的搜索栏设置为启用。 Well i tried that and the seekbar that was disabled would never become enabled even if you touched it i even implemented an ontouchlistener for each seekbar to see if it would become active but it didnt. 好吧,我尝试过,即使您触摸了它,被禁用的搜索栏也永远不会启用。我什至为每个搜索栏都实现了一个ontouchlistener,以查看它是否将变为活动状态,但它没有。 so i have three ways of you guys helping me. 所以我有三种方式来帮助我。 1. Is there a way to edit my method above to get it working the way i want? 1.是否可以通过上面的方法来编辑我的方法,使其以我想要的方式工作? 2. Where can i put my enable seekbar method so that the seekbar only becomes active when the user touches it thus achieving what i stated above? 2.我可以在哪里放置我的启用搜索栏方法,以使搜索栏仅在用户触摸时才激活,从而实现了我上面所述的内容? 3. Is there a way to change a custom seekbars colours in java to achieve what i want 3.有没有一种方法可以更改java中的自定义搜寻栏颜色以实现我想要的

You could try the following: put the SeekBar in a Layout that wrap the SeekBar and put a OnTouchListener on the Layout , then re-enable the SeekBar when the user touches the Layout . 你可以尝试以下方法:把SeekBarLayout是包裹SeekBar ,并把OnTouchListener上的Layout ,然后重新启用SeekBar ,当用户触摸Layout

The color of the SeekBar cannot be easily changed afaik (you need to create colored resources, see this site to generate such resouces). SeekBar的颜色不能轻易更改(您需要创建彩色资源,请访问此站点以生成此类资源)。

If you want to communicate to the user that he can only use one SeekBar at a time, I would, instead of using 如果您想与用户沟通,他一次只能使用一个SeekBar ,那么我将不使用

seekbar.setEnabled(false)

just reduce the alpha of the SeekBar , making it 'pale'. 只需减小SeekBar的alpha值,使其SeekBar “苍白”即可。 Use seekBar.setAlpha() or, if you want to target API levels < 11, use this library 's ViewHelper class. 使用seekBar.setAlpha()或者,如果您希望目标API级别<11,请使用此库的ViewHelper类。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM