2013-06-07 18 views
8

ClickイベントにFramelayourを使用しましたが、2日前に正常に動作していましたが、現在は動作していません。
私を助けてください。
私のコードは以下の通りです: デザイン:FrameLayoutのクリックイベントが発生しない

<FrameLayout 
     android:id="@+id/flWebpre" 
     android:layout_width="fill_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" > 

     <WebView 
      android:id="@+id/wvWebsite" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" /> 

     <ProgressBar 
      android:id="@+id/pbWebsite" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:background="@color/white" 
      android:layout_gravity="center_horizontal" /> 
    </FrameLayout> 

コード:

FrameLayout flWebPre = (FrameLayout) findViewById(R.id.flWebpre); 
    flWebPre.setOnClickListener(new View.OnClickListener() { 

     @Override 
     public void onClick(View v) { 
      // TODO Auto-generated method stub 
      if (isExpanded) { 
       isExpanded = false; 

       new CollapseAnimation(slidingPanel, panelWidth, 
         TranslateAnimation.RELATIVE_TO_SELF, 0.70f, 
         TranslateAnimation.RELATIVE_TO_SELF, 0.0f, 0, 0.0f, 
         0, 0.0f); 
      } 
     } 
    }); 
+1

私はあなたが既に何かをしたけど、あなたはあなたのでframeLayoutのパラメータとして「クリッカブル」を置くことを忘れてしまった知っています。 – Tsunaze

答えて

19

簡単な方法は、すべてのタッチイベントをインターセプトすることです。既定では、ViewGroup#onInterceptTouchEventfalseを返します。

カスタムレイアウトを作成することがあります。

public class ClickableFrameLayout extends FrameLayout { 
    private OnClickListener mOnClickListener; 

    @Override 
    public void setOnClickListener(OnClickListener l) { 
     super.setOnClickListener(l); 
     mOnClickListener = l; 
    } 

    @Override 
    public boolean onInterceptTouchEvent(MotionEvent ev) { 
     return mOnClickListener != null; 
    } 


    // Standard constructors — just pass everything 
    public ClickableFrameLayout(final Context context) { 
     super(context); 
    } 

    public ClickableFrameLayout(final Context context, final AttributeSet attrs) { 
     super(context, attrs); 
    } 

    public ClickableFrameLayout(final Context context, final AttributeSet attrs, final int defStyleAttr) { 
     super(context, attrs, defStyleAttr); 
    } 

    @TargetApi(Build.VERSION_CODES.LOLLIPOP) 
    public ClickableFrameLayout(final Context context, final AttributeSet attrs, final int defStyleAttr, final int defStyleRes) { 
     super(context, attrs, defStyleAttr, defStyleRes); 
    } 
} 
+0

はい、動作していますが、AtributeSetを使用して2番目のコンストラクタを使用していません... – StefMa

+0

は完璧に動作します... thx – Erik255

+0

うわー、どのような完璧なソリューション..! –

関連する問題