【问题标题】:ImageButton Action don't workImageButton 动作不起作用
【发布时间】:2012-02-16 08:27:38
【问题描述】:

我在绝对布局中制作了一些 Imagebuttons,然后使用它的所有按钮旋转整个布局,现在我遇到了一个问题,即 imagebuttons 的操作可能不起作用,因为该操作没有使用 imagebutton 旋转

如果有人知道发生了什么请告诉我

main.xml

<AbsoluteLayout
  android:id="@+id/wheelLayout"
  android:orientation="horizontal"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:layout_weight="1"
  android:layout_x="-250px" android:clickable="true">


    <ImageView
    android:id="@+id/wheelBG"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/wheel"/>

    <ImageButton
        android:id="@+id/accounts"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_x="258dp"
        android:layout_y="222dp"
        android:background="@null"
        android:onClick="accountsOnClick"
        android:src="@drawable/accounts"/>

    <ImageButton
        android:id="@+id/cards"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_x="228dp"
        android:layout_y="291dp"
        android:background="@null"
        android:onClick="cardsOnClick"
        android:src="@drawable/cards"/>
</AbsoluteLayout>

然后我做了一个函数来使用 RotateAnimation 旋转整个绝对布局并在特定的持续时间内倾斜

我已经定义了按钮的动作

public void accountsOnClick(查看视图) { System.out.println("imageButton1OnClick"); }

旋转前动作正常,但旋转后动作不正常

【问题讨论】:

  • 好吧,你的代码有些奇怪,不是吗?
  • 仅供参考,AbsoluteLayout 已弃用
  • 我知道它已被弃用,我在 2.1 平台上工作,我真的需要按圆形顺序放置 Imagebuttons 以适合我的设计,所以我没有找到任何其他布局可以让我设置了 x, y 的项目,除了绝对布局,如果您有任何其他可以帮助的想法,我将不胜感激

标签: android android-layout android-button


【解决方案1】:

您应该使用两种不同的布局。一个在开始动画之前和第二个特殊布局,您可以在动画完成后使用。使用AnimationListener 处理动画完成事件。然后膨胀一个看起来像已经旋转的布局的新布局。

【讨论】:

  • 此解决方案不适用于我的情况,因为动画以不同的角度随机发生,我无法处理所有角度并为每个角度制作不同的布局
  • 其他方式。您可以将 View.OnTouchListener 与父视图或整个活动一起使用。然后您可以监听触摸事件并手动计算 GUI 元素的边框。这太难了,需要很多丑陋的手工工作。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-08-03
  • 2013-12-30
  • 2016-05-04
  • 2019-02-23
相关资源
最近更新 更多