单击/触摸浮动操作按钮不响应 [英] Floating Action Button does not responds when it clicked/touched

查看:235
本文介绍了单击/触摸浮动操作按钮不响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在应用程序中使用浮动操作按钮(FAB)来显示对话框,当我使用Lopllipop 5.1.1在Xperia Z中测试我的应用程序时,一切工作都很好. 但是,问题是,当我的应用程序在使用KitKat 4.4.2的ASUS Zenfone 6中和在使用Jelly Bean 4.2.2的Xperia C中测试我的应用程序时,FAB加载得很好,但是FAB没有显示对话框,似乎当我没有响应时感动了.
作为记录,我的最低SDK版本为16.

I am using a floating action button(FAB) in my application to show Dialogs, everything is worked just fine when I tested my app in Xperia Z with Lopllipop 5.1.1.
However, the problem is when tested my app in ASUS Zenfone 6 with KitKat 4.4.2 and in Xperia C with Jelly Bean 4.2.2, the FAB loaded perfectly but the FAB does not show the Dialogs, seems like it does not responds when I touched it.
For the record, my min sdk version is 16.

我想问的是为什么会这样?我的代码或android版本或API级别有什么问题吗?

What i want to ask is why this is happening? Is there anything wrong with my code, or maybe with the android version or API level?

请看一下我的代码. XML代码如下:

Please take a look at my code. Here the XML code:

    android:id="@+id/fab"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|end"
    android:layout_margin="@dimen/fab_margin"
    android:src="@drawable/ic_add_account"
    android:visibility="invisible"
    android:clickable="true"/>

这里是我如何声明和设置FAB的侦听器:

and here how I declare and set the listener for the FAB:

FloatingActionButton fab;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {

   fab = (FloatingActionButton) getActivity().findViewById(R.id.fab);

   ...
   fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                showDialog();
            }
   });
   ...
}

让我感到困惑的是,它在Xperia Z中是如何工作的,但在华硕Zenfone 6中却不起作用?

The thing that made me confused is how it is worked in Xperia Z but it does not worked in ASUS Zenfone 6?

推荐答案

此处的问题是我在声明listView之前声明了FAB.通过某种方式通过在listView的声明之后重新定位FAB的声明,可以解决此问题.
发件人:

The problem in here is that I declared the FAB before the declaration of listView. Somehow by relocating the declaration of FAB after the the declaration of listView it will solved the problem.
From:

<android.support.design.widget.FloatingActionButton
    ...
    ...
    .../>
<ListView
    ...
    ...
    .../>

收件人:

<ListView
    ...
    ...
    .../>
<android.support.design.widget.FloatingActionButton
    ...
    ...
    .../>

就这么简单.

这篇关于单击/触摸浮动操作按钮不响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆