2016-08-24 46 views
-1

我有一個包含兩個項目的佈局。 A RelativeLayout其中有幾個按鈕和ViewPager。但是,由於按鈕位於ViewPager後面,因此我無法單擊按鈕。有沒有辦法讓我可以點擊ViewPager後面的按鈕?這是我的佈局。Android - 通過viewpager點擊按鈕

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/sliding_down_toolbar_layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:splitMotionEvents="true" 
     android:id ="@+id/content_container"> 

     (Buttons) 

    </RelativeLayout> 

    <android.support.v4.view.ViewPager 
     android:id="@+id/viewpager" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content"/> 
</FrameLayout> 
+0

那麼問題是什麼? – Piyush

+0

你必須解釋你的問題。 –

+0

對不起,我編輯了這個問題。 – nodeDavid

回答

0

試試這個

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      xmlns:app="http://schemas.android.com/apk/res-auto" 
      android:id="@+id/sliding_down_toolbar_layout" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:orientation="vertical"> 

<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="207dp" 
    android:splitMotionEvents="true" 
    android:id ="@+id/content_container"> 


    <Button 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="New Button" 
     android:id="@+id/button" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true" 
     android:layout_marginBottom="54dp"/> 

    <Button 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="New Button" 
     android:id="@+id/button2" 
     android:layout_alignTop="@+id/button" 
     android:layout_toRightOf="@+id/button" 
     android:layout_toEndOf="@+id/button" 
     android:layout_marginLeft="53dp" 
     android:layout_marginStart="53dp"/> 
</RelativeLayout> 

<android.support.v4.view.ViewPager 
    android:id="@+id/viewpager" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"> 

0

我終於設法通過調度從Viewpager觸摸事件,以這樣的content_container做到這一點。

viewpager.setOnTouchListener(new View.OnTouchListener() { 
     @Override 
     public boolean onTouch(View view, MotionEvent motionEvent) { 
      content_container.dispatchTouchEvent(motionEvent); 
      return false; 
     } 
    }); 

感謝您的回答。