ilsswfr 2017-09-03 11:09
浏览 445

求助!!为什么setBisibility要点击5次才有反应.

还有为什么我的提问是0啊...发了好几次

对ImageView设置点击事件,用Log看到应该是点击到了,但是点击事件里的setVisibility要点击五次才能让图片不可见,不知道为啥

全部代码
public class gamelayout extends RelativeLayout {
ImageView imageViews[]=new ImageView[7];

int cnt=0;
private int w;
private int h;

public gamelayout(Context context) {
    this(context,null);
}

public gamelayout(Context context,AttributeSet attrs) {
    this(context, attrs,0);
}
public gamelayout(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
}

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    setMeasuredDimension(1100,1100);
    init();

}

private void init(){
   for (int i=1;i<7;++i){
        imageViews[i]=new ImageView(getContext());
        RelativeLayout.LayoutParams params=new RelativeLayout.LayoutParams(150,150);
        if (i!=1)
            params.addRule(RelativeLayout.RIGHT_OF,imageViews[i-1].getId());
        else
            params.addRule(RelativeLayout.RIGHT_OF);
        addImage(imageViews[i],i);
        addView(imageViews[i],params);
        imageViews[i].setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                Log.d("test",""+(++cnt));
                TES();
                v.setVisibility(INVISIBLE);
            }
        });
    }

}

private void TES() {
    Log.d("tes",""+cnt);
}

private void addImage(ImageView item,int i) {

    item.setId(i);//表示在图标中的下标
    switch(i){
        case 1:item.setImageResource(R.drawable.p1);break;
        case 2:item.setImageResource(R.drawable.p10);break;
        case 3:item.setImageResource(R.drawable.p9);break;
        case 4:item.setImageResource(R.drawable.p15);break;
        case 5:item.setImageResource(R.drawable.p16);break;
        case 6:item.setImageResource(R.drawable.p17);break;
        default:break;
    }
}

}

 <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.edwel.linkgametest2.MainActivity">

    <com.example.edwel.linkgametest2.gamelayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_centerInParent="true"
        />

</RelativeLayout>

09-03 18:28:38.332 24560-24560/com.example.edwel.linkgametest2 D/test: 1
09-03 18:28:38.332 24560-24560/com.example.edwel.linkgametest2 D/tes: 1
09-03 18:28:38.342 24560-24585/com.example.edwel.linkgametest2 D/IMGSRV: gralloc_register_buffer:1390: hnd=0x55a14130d0 ID=15392 fd=71 ref=1
09-03 18:28:38.342 24560-24585/com.example.edwel.linkgametest2 D/GraphicBuffer: register, handle(0x55a14130d0) (w:1080 h:1920 s:1088 f:0x1 u:0x000b00)
09-03 18:28:39.322 24560-24560/com.example.edwel.linkgametest2 V/SettingsInterface: from settings cache , name = sound_effects_enabled , value = 0
09-03 18:28:39.322 24560-24560/com.example.edwel.linkgametest2 D/test: 2
09-03 18:28:39.322 24560-24560/com.example.edwel.linkgametest2 D/tes: 2
09-03 18:28:39.329 24560-24585/com.example.edwel.linkgametest2 D/IMGSRV: gralloc_register_buffer:1390: hnd=0x55a13e8870 ID=15393 fd=74 ref=1
09-03 18:28:39.329 24560-24585/com.example.edwel.linkgametest2 D/GraphicBuffer: register, handle(0x55a13e8870) (w:1080 h:1920 s:1088 f:0x1 u:0x000b00)
09-03 18:28:40.175 24560-24560/com.example.edwel.linkgametest2 V/SettingsInterface: from settings cache , name = sound_effects_enabled , value = 0
09-03 18:28:40.175 24560-24560/com.example.edwel.linkgametest2 D/test: 3
09-03 18:28:40.175 24560-24560/com.example.edwel.linkgametest2 D/tes: 3
09-03 18:28:40.874 24560-24560/com.example.edwel.linkgametest2 V/SettingsInterface: from settings cache , name = sound_effects_enabled , value = 0
09-03 18:28:40.874 24560-24560/com.example.edwel.linkgametest2 D/test: 4
09-03 18:28:40.874 24560-24560/com.example.edwel.linkgametest2 D/tes: 4
09-03 18:28:42.747 24560-24560/com.example.edwel.linkgametest2 V/SettingsInterface: from settings cache , name = sound_effects_enabled , value = 0
09-03 18:28:42.747 24560-24560/com.example.edwel.linkgametest2 D/test: 5
09-03 18:28:42.747 24560-24560/com.example.edwel.linkgametest2 D/tes: 5

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 我这模型写的不对吗?为什么lingo解出来的下面影子价格这一溜少一个变量
    • ¥50 树莓派安卓APK系统签名
    • ¥15 maple软件,用solve求反函数出现rootof,怎么办?
    • ¥65 汇编语言除法溢出问题
    • ¥15 Visual Studio问题
    • ¥20 求一个html代码,有偿
    • ¥100 关于使用MATLAB中copularnd函数的问题
    • ¥20 在虚拟机的pycharm上
    • ¥15 jupyterthemes 设置完毕后没有效果
    • ¥15 matlab图像高斯低通滤波