【发布时间】:2014-07-23 12:10:12
【问题描述】:
我试图让用户在屏幕上的圆圈上放一个戒指,然后按较大的按钮,以便圆圈转到下一个戒指尺寸。
当屏幕上没有响铃时,一切正常。
但是,当它在屏幕上响起时,不会调用其他触摸,并且按钮和搜索栏不起作用。
我是 android 新手,以前没有遇到过这个要求。有没有一种方法可以允许在 Activity 上进行多点触控手势或忽略特定布局上的触摸?
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);
} }
});
}
}
【问题讨论】:
-
请记住,并非所有设备都支持多点触控,因此当您解决此问题时,仍要为用户提供另一种使用环的方式。
-
有没有办法完全忽略或禁用圆形图像上的触摸事件?
-
请重命名您的视图以使您的代码更易于阅读,重新编译并重新运行您的应用程序以确保它仍然像以前一样工作,使用新名称重新发布您的 xml,并发布您的 java 代码。即使没有多点触控,您所描述的症状也不应该发生,所以我怀疑添加多点触控会改变任何事情(除了使代码不必要地更复杂)。这就是为什么我们需要查看您的 java 代码。
-
@StephanBranczyk 我已经添加了您要求的内容。谢谢
标签: android multi-touch seekbar