Android允许多点触摸活动

时间:2014-06-03 08:25:14

标签: android multi-touch seekbar

我试图让用户在屏幕上的圆圈上放一个铃声,然后按下较大的按钮,使圆圈进入下一个铃声大小。

屏幕上没有响铃时,一切都会被罚款。

然而,当它在屏幕上响铃时,没有其他触摸被调用,并且按钮和搜索条不起作用。

我是android的新手,我之前没有遇到过这个要求。有没有办法让我可以在活动上进行多点触控手势,或者忽略对特定布局的触摸?

enter image description here

XML文件

 <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/White" 
    android:splitMotionEvents="false"
    >

<TextView
    android:id="@+id/us"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_toRightOf="@+id/uslbl"
    android:padding="@dimen/standard_margin"
    android:text="size"
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:textColor="@color/pressed_gemporia" />

<TextView
    android:id="@+id/uklbl"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/uslbl"
    android:padding="@dimen/standard_margin"
    android:text="UK Size:"
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:textColor="@color/Black" />

<TextView
    android:id="@+id/uk"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBaseline="@+id/uklbl"
    android:layout_alignBottom="@+id/uklbl"
    android:layout_toRightOf="@+id/uklbl"
    android:padding="@dimen/standard_margin"
    android:text="size"
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:textColor="@color/pressed_gemporia" />

<ImageView
    android:id="@+id/ci"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true" />

<TextView
    android:id="@+id/uslbl"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentStart="true"
    android:layout_alignParentTop="true"
    android:layout_toLeftOf="@+id/uk"
    android:gravity="left"
    android:padding="@dimen/standard_margin"
    android:text="US Size:"
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:textColor="@color/Black" />

<SeekBar
    android:id="@+id/seekbar"
   android:progressDrawable="@drawable/red_scrubber_progress"
android:thumb="@drawable/red_scrubber_control"

     android:max="8"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/divider" />

<View
    android:id="@+id/divider"
    android:layout_width="fill_parent"
    android:layout_height="1dp"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/uklbl"
    android:layout_marginTop="18dp"
    android:background="@color/pressed_gemporia" />




<TextView
    android:id="@+id/sizes"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
      android:padding="@dimen/standard_margin"
    android:layout_below="@+id/seekbar"
    android:text="TextView"    android:textColor="@color/pressed_gemporia"  />

<Button
    android:id="@+id/right"
    android:layout_width="100dp"
    android:textColor="@color/pressed_gemporia" 
    android:layout_height="wrap_content"
           android:background="@color/White" 
    android:layout_alignParentRight="true"
    android:layout_alignTop="@+id/left"
    android:text="Larger" />

<Button
    android:id="@+id/left"
    android:layout_width="100dp"
                   android:background="@color/White" 
    android:textColor="@color/pressed_gemporia" 
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:text="Smaller" />

<ImageView
    android:id="@+id/ring"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/ci"
    android:layout_centerHorizontal="true"
    android:src="@drawable/j" />

Java代码

  protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
         setContentView(R.layout.ring_sizes);

         left = (Button)findViewById(R.id.left);
         right = (Button)findViewById(R.id.right);
         us = (TextView)  findViewById(R.id.us);
         uk = (TextView)  findViewById(R.id.uk);
         ci = (ImageView)findViewById(R.id.ci);
         ring = (ImageView)findViewById(R.id.ring);
         sizes.add(R.drawable.j);
         sizes.add(R.drawable.l);
         sizes.add(R.drawable.n);
         sizes.add(R.drawable.p);
         sizes.add(R.drawable.r);
         sizes.add(R.drawable.t);
         sizes.add(R.drawable.v);
         sizes.add(R.drawable.x);
         sizes.add(R.drawable.z);

         USsizes.add("5");
         USsizes.add("6");      
         USsizes.add("7");       
         USsizes.add("8");       
         USsizes.add("9");      
         USsizes.add("10");      
         USsizes.add("11");      
         USsizes.add("12");      
         USsizes.add("13");      

         UKsizes.add("J-K");
         UKsizes.add("L-M");        
         UKsizes.add("N-O");         
         UKsizes.add("P-Q");         
         UKsizes.add("R-S");        
         UKsizes.add("T-U");         
         UKsizes.add("V-W");         
         UKsizes.add("X-Y");         
         UKsizes.add("Z+"); 

         color = (getBaseContext().getResources().getColor(R.color.pressed_gemporia));
         value = (TextView) findViewById(R.id.sizes);
         seekbar = (SeekBar) findViewById(R.id.seekbar);


         seekbar.getProgressDrawable().setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.MULTIPLY));

          value.setText("UK Size : "+UKsizes.get(0) + " - US Size: " + USsizes.get(0));
             setUpViews();
                                        seekbar.setOnSeekBarChangeListener( new OnSeekBarChangeListener()
        {
        public void onProgressChanged(SeekBar seekBar, int progress,
                                                                        boolean fromUser)
        {

            ring.setImageResource(sizes.get(progress));

                us.setText(USsizes.get(progress));
                uk.setText(UKsizes.get(progress));
                counter=progress;


value.setText("UK Size : "+UKsizes.get(progress) + " - US Size: " + USsizes.get(progress));

                                                        }

         public void onStartTrackingTouch(SeekBar seekBar)
        {
                   // TODO Auto-generated method stub
                                                        }

     public void onStopTrackingTouch(SeekBar seekBar)
        {
         // TODO Auto-generated method stub
                                                        }
        });


    }


    public void setUpViews(){


        ring.setImageResource(sizes.get(counter));

            us.setText(USsizes.get(counter));
            uk.setText(UKsizes.get(counter));


             right.setOnClickListener(new View.OnClickListener()
             {
                 @Override
                 public void onClick(View view)
                 {
                     if(UKsizes.size()>counter+1){

                            ring.setImageResource(sizes.get(counter+1));


                 seekbar.setProgress(counter+1);


                     }

                 }
             });


             left.setOnClickListener(new View.OnClickListener()
             {
                 @Override
                 public void onClick(View view)
                 {
                     if(counter!=0){

                            ring.setImageResource(sizes.get(counter));

                 seekbar.setProgress(counter-1);




                     } }
             });





    }

}

1 个答案:

答案 0 :(得分:0)

有一种方法可以忽略特定布局中的触摸,因为你应该添加

 android:splitMotionEvents="false"

在您的布局中。您可以通过以下链接查询答案 https://stackoverflow.com/questions/12777435/disable-multi-finger-touch-in-my-app