2013-06-07 44 views
8

Tôi đã sử dụng Framelayour cho sự kiện nhấp chuột và nó hoạt động tốt trước 2 ngày nhưng không biết wat happend bây giờ nó không hoạt động.
Vui lòng ai đó giúp tôi.
Mã của tôi là như sau: Thiết kế:FrameLayout nhấp vào sự kiện không phải là bắn

<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> 

Code:

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

Tôi biết bạn đã làm một cái gì đó, nhưng bạn quên đặt "nhấp được" như một tham số trong FrameLayout của bạn. – Tsunaze

Trả lời

19

Một cách dễ dàng là để đánh chặn tất cả các sự kiện liên lạc. Theo mặc định, ViewGroup#onInterceptTouchEvent trả lại false.

Bạn có thể tạo một bố cục tùy chỉnh:

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

có nó đang hoạt động, nhưng bạn đã tha thứ cho nhà xây dựng thứ hai với AtributeSet ... – StefMa

+0

hoạt động hoàn hảo ... thx – Erik255

+0

Wow, giải pháp hoàn hảo là gì ..! –

Các vấn đề liên quan