2013-04-29 41 views
1

我對裝配兩個自定義視圖一起工作真的很惱人的問題。我試圖在Android活動中顯示這兩個視圖,但其中一個需要整個活動的可視空間,另一個放在它的下面。第一個視圖只使用了一小部分空間,其餘部分是透明的,但只有當它的寬度和高度爲match_parent時才起作用,因此另一個視圖顯示在其下,但它不能接收任何觸摸事件。這裏是他們的樣子:底部視圖被頂視圖擋住了

1

2

XML代碼:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:background="@color/background_app" > 

<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 

    <com.fortysevendeg.android.swipelistview.SwipeListView 
     xmlns:swipe="http://schemas.android.com/apk/res-auto" 
     android:id="@+id/example_lv_list" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:listSelector="#00000000" 
     swipe:swipeActionLeft="dismiss" 
     swipe:swipeBackView="@+id/back" 
     swipe:swipeCloseAllItemsWhenMoveList="true" 
     swipe:swipeFrontView="@+id/front" 
     swipe:swipeMode="both" 
     android:focusableInTouchMode="true"/> 
</LinearLayout> 

<com.touchmenotapps.widget.radialmenu.semicircularmenu.SemiCircularRadialMenu 
     android:id="@+id/radial_menu" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_gravity="bottom" 
     android:padding="1dip" /> 
</FrameLayout> 

我想要做的是能觸及底部,其中頂部視圖是透明的,並且能夠觸摸不透明的頂視圖。我嘗試以不同的方式安排xml,但它不斷崩潰,這是它工作的唯一方式,但出現了這個問題。

鏈接到自定義瀏覽:

  • 徑向菜單,窗口小部件:github.com/strider2023/Radial-Menu-Widget-Android
  • SwipeListView庫:github.com/47deg/android-swipelistview
  • SwipeListView樣本:github.com/47deg/android-swipelistview-sample

我想在這裏實現類似於Catch Notes應用的東西。如果還有其他的方式,或者你可以建議的其他圖書館,這將是非常感謝。

回答

1

好試試這個:在你的項目中複製的SemiCircularRadialMenu.class源代碼並修改

public boolean onTouchEvent(MotionEvent event) 

因爲這種方法總是返回true,並捕獲所有的觸摸事件,因此也爲SwipeListView監聽的觸摸事件。我以這種方式解決了這個問題。

0

一個老問題,但其他人可能會發現這個答案有幫助。不修改您的自定義視圖的來源,我不認爲你可以得到你想要的行爲。但是讓兩個自定義視圖在同一個屏幕上工作可能就像將根佈局更改爲LinearLayout一樣簡單,向內部佈局添加重量並將第二個自定義視圖的高度設置爲wrap_content。通過只有一個具有重量的小部件,在其他人佈置之後它將獲得剩下的所有空間。這是你的佈局與應用的更改:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@color/background_app" 
    android:orientation="vertical" > 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="0dip" 
     android:layout_weight="100" > 

     <com.fortysevendeg.android.swipelistview.SwipeListView 
      xmlns:swipe="http://schemas.android.com/apk/res-auto" 
      android:id="@+id/example_lv_list" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:focusableInTouchMode="true" 
      android:listSelector="#00000000" 
      swipe:swipeActionLeft="dismiss" 
      swipe:swipeBackView="@+id/back" 
      swipe:swipeCloseAllItemsWhenMoveList="true" 
      swipe:swipeFrontView="@+id/front" 
      swipe:swipeMode="both" /> 
    </LinearLayout> 

    <com.touchmenotapps.widget.radialmenu.semicircularmenu.SemiCircularRadialMenu 
     android:id="@+id/radial_menu" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="bottom" 
     android:padding="1dip" /> 

</LinearLayout> 

如果需要第二個觀點的高度更可擴展,你可以用它與重另一個LinearLayout中,並調整兩個權重分配之間的屏幕高度他們。個人體重值並不特殊;這是他們的價值,相對於所有權重的總和來決定每個人獲得多少高度。我想讓我的總價值加起來達到100,所以我可以將權重看作百分比。