2011-02-22 97 views
0

首先,我認爲問題會很容易解決,但事實證明這是一個挑戰。FrameLayout onClick在Android上重疊圖像

場景 一個FrameLayout和兩個ImageViews,一個在另一個之上。第一張圖片有翻譯動畫和onClick事件。讓我們在實際中進行翻譯:Framelayout有一張兔子圖片和一張布什圖片。兔子有一個翻譯動畫,所以它移出灌木叢。只要兔子變得可見,用戶就可以點擊它。不幸的是,這不符合預期。即使兔子不能看到(在叢林後面),如果用戶敲擊灌木叢,兔子的咔嗒聲也會發生。我試圖爲灌木圖像添加onClick事件(沒有做任何事情),但現在只有這一個事件發生,而兔子事件不會。

代碼

動畫

<?xml version="1.0" encoding="utf-8"?> 
<translate 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:fromXDelta="0%" 
    android:toXDelta="100%" 
    android:fromYDelta="0%" 
    android:toYDelta="0%" 
    android:duration="25000" 
    android:zAdjustment="top" /> 

佈局

<?xml version="1.0" encoding="utf-8"?> 
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       android:id="@+id/layBackground" 
       android:orientation="horizontal" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:layout_weight="1" 
       android:background="@drawable/someimage"> 

         <ImageView android:id="@+id/imgAfterBush" 
           android:layout_width="wrap_content" 
           android:layout_height="wrap_content" 
           android:layout_gravity="bottom|left" 
           android:layout_marginLeft="50dip" 
           android:onClick="imgAfterBushOnClick"/> 

         <ImageView android:id="@+id/imgBush" 
           android:layout_width="wrap_content" 
           android:layout_height="wrap_content" 
           android:src="@drawable/bush" 
           android:layout_gravity="bottom|left" 
           /> 
</FrameLayout> 

我希望兔年圖像的onclick事件火災只有當它是可見的。任何解決方案謝謝。

回答

2

Android上的動畫< 3.0僅影響視圖的渲染:您設置的視圖仍處於原始位置。當動畫結束時,您需要自己移動視圖(例如通過更改其佈局參數)。

+0

謝謝你的答案,但我不明白。如果用戶在運行時無法與其交互,那麼有什麼意思?用戶需要能夠在動畫時點擊圖像視圖,而不是當它結束時.Hmm ...這意味着我需要實現我自己的動畫系統,並在計時器上更改視圖參數。對於這樣一個基本的東西?還有什麼其他解決方案適合我的情況? – Alin 2011-02-22 17:52:41

+0

似乎值得注意的是,如果你採用這種方法(在動畫完成後移動視圖),兔子ImageView在動畫時不會被點擊。如果小兔子ImageView正在緩慢地從叢林ImageView下爬出來,並且用戶應該可以隨時點擊它,這將不適合您的需求。 – spaaarky21 2013-05-02 17:22:29