布局为:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
>
<ImageView android:id="@+id/imgmain"
android:layout_width="fill_parent"
android:layout_height="fill_parent" android:src="@drawable/cover1"/>
<ImageView android:id="@+id/back"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:src="@drawable/back"
android:layout_alignLeft="@+id/imgmain"
android:layout_alignTop="@+id/imgmain" android:paddingTop="40dip" android:paddingLeft="26dip"/>
<ImageView android:id="@+id/setup"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:src="@drawable/setup"
android:layout_alignRight="@+id/imgmain"
android:layout_alignTop="@+id/imgmain" android:paddingTop="40dip" android:paddingRight="24dip"/>
<ImageView android:id="@+id/point1"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:src="@drawable/point"
android:layout_alignRight="@id/imgmain"
android:layout_alignBottom="@id/imgmain" android:paddingBottom="52dip" android:paddingRight="32dip"/>
<ImageView android:id="@+id/point2"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:src="@drawable/setup"
android:layout_alignRight="@id/imgmain"
android:layout_alignBottom="@id/imgmain" android:paddingBottom="202dip" android:paddingRight="32dip"/>
<ImageView android:id="@+id/point3"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:src="@drawable/back"
android:layout_alignRight="@id/imgmain"
android:layout_alignBottom="@id/imgmain" android:paddingBottom="202dip" android:paddingRight="122dip"/>
</RelativeLayout>
</LinearLayout>程序为:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.point);
img_main = (ImageView) findViewById(R.id.imgmain);
img_main.setImageResource(R.drawable.point_main);
img_main.setOnClickListener(this);
img_setup = (ImageView) findViewById(R.id.setup);
img_back = (ImageView) findViewById(R.id.back);
img_setup.setVisibility(View.INVISIBLE);
//img_main.setOnClickListener(this);
img_back.setOnClickListener(this);
img_point1 = (ImageView) findViewById(R.id.point1);
img_point2 = (ImageView) findViewById(R.id.point2);
img_point3 = (ImageView) findViewById(R.id.point3);
img_point1.setOnTouchListener(new OnTouchListener(){
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
//Toast.makeText(Point.this, "point_do_new1", Toast.LENGTH_SHORT).show();
img_main.setImageResource(R.drawable.point_do_new1);
IsClick=1;
return false;
}});
img_point2.setOnTouchListener(new OnTouchListener(){
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
//Toast.makeText(Point.this, "point_do_new1", Toast.LENGTH_SHORT).show();
img_main.setImageResource(R.drawable.point_do_new2);
IsClick=1;
return false;
}});
img_point3.setOnTouchListener(new OnTouchListener(){
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
//Toast.makeText(Point.this, "point_do_new1", Toast.LENGTH_SHORT).show();
img_main.setImageResource(R.drawable.point_play_new1);
IsClick=1;
return false;
}});
}
public void onClick(View v) {
// TODO Auto-generated method stub
if (v == img_back) {
if (IsClick==0)
{
Intent intent = new Intent();// 得到一个意图的实例
intent.setClass(this, ViewPlay.class);// 设置当前activity以及将要操作的类
this.setResult(RESULT_OK, intent);
this.finish();
}
else
{
img_main.setImageResource(R.drawable.point_main);
IsClick=0;
}
}
}
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
return false;
}
问题就是 img_point1、img_point2、img_point3的onTouch 无论点击 哪个 都是最后一个起作用 也就是说 哪段代码 写在后面 就是哪段代码起作用
目前起作用的就是 img_point3.setOnTouchListener(new OnTouchListener(){
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
//Toast.makeText(Point.this, "point_do_new1", Toast.LENGTH_SHORT).show();
img_main.setImageResource(R.drawable.point_play_new1);
IsClick=1;
return false;
}});img_point1、img_point2 事件 好像根本没有触发 有人知道是怎么回事吗?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
>
<ImageView android:id="@+id/imgmain"
android:layout_width="fill_parent"
android:layout_height="fill_parent" android:src="@drawable/cover1"/>
<ImageView android:id="@+id/back"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:src="@drawable/back"
android:layout_alignLeft="@+id/imgmain"
android:layout_alignTop="@+id/imgmain" android:paddingTop="40dip" android:paddingLeft="26dip"/>
<ImageView android:id="@+id/setup"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:src="@drawable/setup"
android:layout_alignRight="@+id/imgmain"
android:layout_alignTop="@+id/imgmain" android:paddingTop="40dip" android:paddingRight="24dip"/>
<ImageView android:id="@+id/point1"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:src="@drawable/point"
android:layout_alignRight="@id/imgmain"
android:layout_alignBottom="@id/imgmain" android:paddingBottom="52dip" android:paddingRight="32dip"/>
<ImageView android:id="@+id/point2"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:src="@drawable/setup"
android:layout_alignRight="@id/imgmain"
android:layout_alignBottom="@id/imgmain" android:paddingBottom="202dip" android:paddingRight="32dip"/>
<ImageView android:id="@+id/point3"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:src="@drawable/back"
android:layout_alignRight="@id/imgmain"
android:layout_alignBottom="@id/imgmain" android:paddingBottom="202dip" android:paddingRight="122dip"/>
</RelativeLayout>
</LinearLayout>程序为:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.point);
img_main = (ImageView) findViewById(R.id.imgmain);
img_main.setImageResource(R.drawable.point_main);
img_main.setOnClickListener(this);
img_setup = (ImageView) findViewById(R.id.setup);
img_back = (ImageView) findViewById(R.id.back);
img_setup.setVisibility(View.INVISIBLE);
//img_main.setOnClickListener(this);
img_back.setOnClickListener(this);
img_point1 = (ImageView) findViewById(R.id.point1);
img_point2 = (ImageView) findViewById(R.id.point2);
img_point3 = (ImageView) findViewById(R.id.point3);
img_point1.setOnTouchListener(new OnTouchListener(){
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
//Toast.makeText(Point.this, "point_do_new1", Toast.LENGTH_SHORT).show();
img_main.setImageResource(R.drawable.point_do_new1);
IsClick=1;
return false;
}});
img_point2.setOnTouchListener(new OnTouchListener(){
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
//Toast.makeText(Point.this, "point_do_new1", Toast.LENGTH_SHORT).show();
img_main.setImageResource(R.drawable.point_do_new2);
IsClick=1;
return false;
}});
img_point3.setOnTouchListener(new OnTouchListener(){
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
//Toast.makeText(Point.this, "point_do_new1", Toast.LENGTH_SHORT).show();
img_main.setImageResource(R.drawable.point_play_new1);
IsClick=1;
return false;
}});
}
public void onClick(View v) {
// TODO Auto-generated method stub
if (v == img_back) {
if (IsClick==0)
{
Intent intent = new Intent();// 得到一个意图的实例
intent.setClass(this, ViewPlay.class);// 设置当前activity以及将要操作的类
this.setResult(RESULT_OK, intent);
this.finish();
}
else
{
img_main.setImageResource(R.drawable.point_main);
IsClick=0;
}
}
}
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
return false;
}
问题就是 img_point1、img_point2、img_point3的onTouch 无论点击 哪个 都是最后一个起作用 也就是说 哪段代码 写在后面 就是哪段代码起作用
目前起作用的就是 img_point3.setOnTouchListener(new OnTouchListener(){
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
//Toast.makeText(Point.this, "point_do_new1", Toast.LENGTH_SHORT).show();
img_main.setImageResource(R.drawable.point_play_new1);
IsClick=1;
return false;
}});img_point1、img_point2 事件 好像根本没有触发 有人知道是怎么回事吗?
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货