2

我有一个应用程序,在其中我将一些图像设置为固定角度。在 270 到 90 角度之间的角度,我使用不可见隐藏图像。但它的触摸事件仍然有效。显然因为图像在那里。我想以编程方式禁用触摸这些角度的事件。任何人都可以指导我如何实现这一点。

这是我在 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);
            }

它工作正常。

对于旋转,我称之为这种方法

    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
        }

这是我的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" />
4

3 回答 3

0

使用 if (angle >= 270 && angle <= 90) { image.setVisibility(View.GONE); 它将解决您的问题

于 2013-10-31T08:35:10.637 回答
0
if(angle >=270 && angle <=90){ image.setEnabled(false)} //I guess when you add the image

或者如果由于某种原因无法正常工作,请检查点击:

image.setOnClickListener(new View.OnClickListener(){
  @Override
  public void onClick(View v){
    if(!(angle >=270 && angle <=90)){
      //handle click
    }
  }
}
于 2013-10-31T08:40:36.057 回答
0

首先,您需要以编程方式检查视图是否可见。使用此代码检查可见性

image.setOnClickListener(new OnClickListener() {

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

        }
    });
于 2013-10-31T08:42:07.703 回答