2

I have an application in which i set some images at fix angles.At angle between 270 to 90 angle ,i hide the images by using invisible.but still its touch event working.obviously because images are there.i want to programmatically disable the touch event at these angles.can anybody guide me how to implement this.

this is my code in onLayout-

float angleDelay = 360 / getChildCount();
    if (!childRotate) {

        for (Integer i = 0; i < childCount; i++) {
            final Left_Unit textName = (Left_Unit) getChildAt(i);

            if (textName.getVisibility() == GONE) {
                continue;
            }

            if (angle > 360) {
                angle -= 360;
            } else {
                if (angle < 0) {
                    angle += 360;
                }
            }
            textName.setAngle(angle);
            textName.setPosition(i);
            if (position == name.size()) {
                position = 0;
            }
            if (position < childCount) {
                // textName.setVisibility(View.VISIBLE);

                textName.setTextname(name.get(position));
                textName.setText(name.get(position));
                position++;

            }
            if (angle <= 270 && angle >= 90) {
                textName.setVisibility(View.VISIBLE);
            }

it works fine.

for rotation,i called this method

    for (Integer i = 0; i < childCount; i++) {

        if (angle > 360) {
            angle -= 360;
        } else {
            if (angle < 0) {
                angle += 360;
            }
        }
        final Left_Unit child = (Left_Unit) getChildAt(i);
        if (child.getVisibility() == GONE) {
            continue;
        }
        if (position == name.size()) {
            position = 0;
        }
        if (angle > 85 && angle < 90) {
            // child.setVisibility(View.VISIBLE);

            child.setTextname(name.get(position));
            child.setText(name.get(position));
            position++;
        }
        if (angle <= 270 && angle >= 90) {
            child.setVisibility(View.VISIBLE);
        } else {
            child.setVisibility(View.GONE);//when i use View.INVISIBLE it works fine & images become visible after rotation but with gone it's not visible again
        }

and this is my xml

                <com.example.converter.view.Left_Unit
                    android:id="@+id/text1"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="a1"
                    android:textColor="#ffffff"
                    android:visibility="invisible"
                    left:textname="text1" />
gbl
  • 178
  • 2
  • 12

3 Answers3

0

Use if (angle >= 270 && angle <= 90) { image.setVisibility(View.GONE); } it will solve your problem

Amit Gupta
  • 1,067
  • 13
  • 26
  • problem is with ontouch not with the visibility. – gbl Oct 31 '13 at 08:36
  • I also face same kind of problem but if you hide your image with view.INVISIBLE it will hide the image but remains in touch mode but if you use View.Gone it will hide the image and also disable in touch mode. It solves my problem – Amit Gupta Oct 31 '13 at 08:47
  • actually in xml,i set the visibility to invisible.so when i use if (angle >= 270 && angle <= 90) { image.setVisibility(View.GONE); } it work fine after that it's not display again. i wrote if (angle >= 270 && angle <= 90) { image.setVisibility(View.GONE); }else { image.setVisibility(View.VISIBLE);} but it's not working – gbl Oct 31 '13 at 08:59
  • 1
    What i think that there is some other problem with your code because I use View.Gone and View.Visible several times but never face any kind of problem so share your code it will help me to understand the problem – Amit Gupta Oct 31 '13 at 09:06
  • Ok glb do one more thing remove android:visibility="invisible" and use setvisibility View.Gone in the class file where you want to hide the image. – Amit Gupta Oct 31 '13 at 09:28
  • i tried that too.i remove the android:visibility="invisible" from xml and in onLayout wrote if (angle <= 270 && angle >= 90) { child.setVisibility(View.VISIBLE); } else { child.setVisibility(View.GONE); } bt still not working. – gbl Oct 31 '13 at 09:55
  • i found the error.it was due to if (textName.getVisibility() == GONE) {continue; } but it still rotate – gbl Oct 31 '13 at 10:05
  • ok use this iv.setFocusable(false); iv.setFocusableInTouchMode(false); – Amit Gupta Oct 31 '13 at 10:18
0
if(angle >=270 && angle <=90){ image.setEnabled(false)} //I guess when you add the image

or if that can't work for some reason, check on click:

image.setOnClickListener(new View.OnClickListener(){
  @Override
  public void onClick(View v){
    if(!(angle >=270 && angle <=90)){
      //handle click
    }
  }
}
J2K
  • 1,593
  • 13
  • 26
0

First you need to check whether the view is visible or not programmatically. Use this code to check the visibility

image.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
           if (v.getVisibility() == View.VISIBLE) {
                         // Its visible
                        } else {
                           do nothing
                           }    

        }
    });
Akhilesh Sk
  • 451
  • 4
  • 18