我有一个应用程序,在其中我将一些图像设置为固定角度。在 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" />