2015-03-30 87 views
0

经过一些尝试后,我能够生成一个半透明的背景,当我点击我的浮动按钮。现在的问题是,“新背景”只会改变颜色。在此之下,我有一个回收视图,我仍然可以向上或向下swype并与之交互。我现在需要的是在布局下使用recyclerview来阻止每个动作,让我可见。我能做的唯一的事情就是:防止触摸一个视图android

  • 如果我在半透明视图中单击晶圆厂崩溃

这是实际使用的代码:

OnClickListener listener = new OnClickListener() 
    { 
     @Override 
     public void onClick(View v) 
     { 
      if (DrawerActivity.instance.rootFab.isExpanded()) 
      { 
       whiteLayout.setVisibility(View.GONE); 
      } 
      else 
      { 
       whiteLayout.setVisibility(View.VISIBLE); 

      } 
      mainFab.toggle(); 
     } 
    }; 

,当然还有:

rootFab.setAddButtonClickListener(listener); 

给它听者。所以,简单地说,点击主晶圆厂(我用多个晶圆厂库),它使可见的就是喜欢的布局:

---- 
---- 
<android.support.v7.widget.RecyclerView 
      android:id="@android:id/list" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_below="@+id/status" 
      android:clipToPadding="false" 
      android:scrollbars="vertical" /> 
     <LinearLayout 
      android:id="@+id/semi_white_bg" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:background="@color/white_semi_transparent" 
      android:orientation="vertical" 
      android:visibility="gone" > 
     </LinearLayout> 
--- 
--- 

如果我按工厂重新布局消失...所以我的问题是,我怎么能做同样的事情,但点击这个背景,但没有“接触”它的recyclerview?

回答

2

您可以告诉Android您的视图是“可点击”的。这样您的视图将消耗触摸事件,并且它们不会继续传递到RecyclerView

为了纪念视图“点击”只需添加以下标志到你的XML布局:android:clickable="true"

---- 
---- 
<android.support.v7.widget.RecyclerView 
      android:id="@android:id/list" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_below="@+id/status" 
      android:clipToPadding="false" 
      android:scrollbars="vertical" /> 
     <LinearLayout 
      android:id="@+id/semi_white_bg" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:background="@color/white_semi_transparent" 
      android:orientation="vertical" 
      android:clickable="true" 
      android:visibility="gone" > 
     </LinearLayout> 
--- 
--- 

另外,如果你用你的观点只是一个背景 - 我看不出有任何理由为什么你需要重量为LinearLayout。您可以在这里使用View

---- 
---- 
<android.support.v7.widget.RecyclerView 
      android:id="@android:id/list" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_below="@+id/status" 
      android:clipToPadding="false" 
      android:scrollbars="vertical" /> 
     <View 
      android:id="@+id/semi_white_bg" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:background="@color/white_semi_transparent" 
      android:clickable="true" 
      android:visibility="gone" /> 
--- 
--- 
+0

是的,事实上,我更新了代码与视图。顺便说一句,正确!现在我的观点被标记为可点击。我无法再触碰RecyclerView。但是,我可以在视图上创建一个onClick方法,以使可能如果触及晶圆厂崩溃和视图消失?即使现在是android:clickable =“true”? – 2015-03-30 22:33:43

+0

当然,'onClickListener'仍然可以添加 – 2015-03-30 22:35:29

+0

不错,谢谢! – 2015-03-30 22:40:09