Frage

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" />
War es hilfreich?

Lösung

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

Andere Tipps

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
                           }    

        }
    });
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
    }
  }
}
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top