綁定帳號登入

Android 台灣中文網

打印 上一主題 下一主題

[求助] android imageview setOnTouchListener

[複製連結] 查看: 1359|回覆: 7|好評: 0
跳轉到指定樓層
樓主
deenya | 收聽TA | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
發表於 2013-5-3 14:13

馬上加入Android 台灣中文網,立即免費下載應用遊戲。

您需要 登錄 才可以下載或查看,沒有帳號?註冊

x
我想請問,我有兩個imageview,當我兩個個別使用touch事件時,都會試第2各imageview有行為
例如
test = (ImageView) findViewById(R.id.aIma);
test.setOnTouchListener(new View.OnTouchListener() {}

test1 = (ImageView) findViewById(R.id.bIma);
test1.setOnTouchListener(new View.OnTouchListener() {}

當我點test,有行為的卻是test1
請問我該怎做
請各位指導,謝謝
「用Android 就來APK.TW」,快來加入粉絲吧!
Android 台灣中文網(APK.TW)
收藏收藏 分享分享 分享專題
用Android 就來Android 台灣中文網(https://apk.tw)
回覆

使用道具 舉報

沙發
clotai | 收聽TA | 只看該作者
發表於 2013-5-4 17:44
把你的 Layout xml post 上來. 這樣沒辦法知道你問題.
我猜你 test1 直接蓋到 test  了.
所以你 touch event 都被 test1 消耗掉了.
用Android 就來Android 台灣中文網(https://apk.tw)
回覆 支持 反對

使用道具 舉報

板凳
 樓主| deenya | 收聽TA | 只看該作者
發表於 2013-5-6 10:44

   附上xml代碼
   <FrameLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
                                       >

        <ImageView
            android:id="@+id/aIma"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="0.41"
            android:scaleType="matrix"
            android:src="@drawable/a"
            android:paddingLeft="10dp"
            android:paddingTop="5dp"
            android:paddingRight="10dp"
              />

        <ImageView
            android:id="@+id/bIma"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="0.66"
            android:scaleType="matrix"
            android:src="@drawable/b"
             android:paddingLeft="100dp"
            android:paddingTop="5dp"
            android:paddingRight="10dp"
            />


    </FrameLayout>
用Android 就來Android 台灣中文網(https://apk.tw)
回覆 支持 反對

使用道具 舉報

地板
clotai | 收聽TA | 只看該作者
發表於 2013-5-6 10:49

android:paddingLeft="100dp" 你這個是打錯嗎?
用Android 就來Android 台灣中文網(https://apk.tw)
回覆 支持 反對

使用道具 舉報

5
 樓主| deenya | 收聽TA | 只看該作者
發表於 2013-5-6 11:36
clotai 發表於 2013-5-6 10:49
android:paddingLeft="100dp" 你這個是打錯嗎?

沒有打錯
我只是要離左邊開一點
用Android 就來Android 台灣中文網(https://apk.tw)
回覆 支持 反對

使用道具 舉報

6
clotai | 收聽TA | 只看該作者
發表於 2013-5-6 11:47
你這邊不能使用 FrameLayout, 你的 第二個 image 覆蓋到第一個 image 了,
下面這 layout file 你測一下.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="horizontal">

    <ImageView
        android:id="@+id/aIma"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="0.41"
        android:paddingLeft="10dp"
        android:paddingRight="10dp"
        android:paddingTop="5dp"
        android:scaleType="matrix"
        android:src="@drawable/ic_launcher" />

    <ImageView
        android:id="@+id/bIma"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="0.66"
        android:paddingLeft="50dp"
        android:paddingRight="10dp"
        android:paddingTop="5dp"
        android:scaleType="matrix"
        android:src="@drawable/ic_launcher" />

</LinearLayout>

評分

參與人數 1幫助 +1 收起 理由
ploglin + 1

查看全部評分

用Android 就來Android 台灣中文網(https://apk.tw)
回覆 支持 反對

使用道具 舉報

7
clotai | 收聽TA | 只看該作者
發表於 2013-5-6 11:48
deenya 發表於 2013-5-6 11:36
沒有打錯
我只是要離左邊開一點

把 FrameLayout 改用 LinearLayout, 這問題就可以解決.
你的 第二個 Image 覆蓋到第一個 Image 了.

評分

參與人數 1幫助 +1 收起 理由
ploglin + 1

查看全部評分

用Android 就來Android 台灣中文網(https://apk.tw)
回覆 支持 反對

使用道具 舉報

8
 樓主| deenya | 收聽TA | 只看該作者
發表於 2013-5-6 14:28
clotai 發表於 2013-5-6 11:48
把 FrameLayout 改用 LinearLayout, 這問題就可以解決.
你的 第二個 Image 覆蓋到第一個 Image 了. ...

喔喔~~了解
謝謝你的協助
用Android 就來Android 台灣中文網(https://apk.tw)
回覆 支持 反對

使用道具 舉報

您需要登錄後才可以回帖 登錄 | 註冊

本版積分規則