ImageButton点击失效

我在现在这个项目开发的过程中,遇到了ImageButton点击失效的问题,百思不得其解,甚至开始怀疑人生了,终于发现问题的原因,先上布局代码.


<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/video_view_bg_color"
    android:orientation="vertical"
    tools:context=".activity.ShareActivity">

        <com.rinogame.aiduke.view.TitleView
            android:id="@+id/view5"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"
            app:text=""/>

        <RelativeLayout
            android:id="@+id/relative_play"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/view5"
            android:layout_margin="@dimen/margin_5dp"
            android:background="@drawable/common_round_corner">

            <org.wysaid.view.VideoPlayerGLSurfaceView
                android:id="@+id/videoView"
                android:layout_width="match_parent"
                android:layout_height="300dp"
                android:layout_gravity="center_horizontal"
                android:layout_margin="@dimen/margin_8dp"/>

            <ImageView
                android:id="@+id/save_activity_btn_play"
                android:layout_width="match_parent"
                android:layout_height="@dimen/height_300dp"
                android:layout_gravity="center"
                android:background="@drawable/common_round_corner"
                android:visibility="visible"/>
        </RelativeLayout>

        <FrameLayout
            android:id="@+id/frame_input"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_above="@+id/linear_share"
            android:layout_below="@+id/relative_play"
            android:background="#1b242D"
            >

            <android.support.design.widget.TextInputLayout
                android:id="@+id/save_activity_ti"
                android:layout_width="match_parent"
                android:layout_height="@dimen/height_100dp"
                android:layout_margin="@dimen/margin_8dp"
                android:background="@drawable/common_round_corner"
                app:hintTextAppearance="@style/hintStyle">

                <EditText
                    android:id="@+id/save_activity_tv_share_content"
                    android:layout_width="match_parent"
                    android:layout_height="@dimen/height_150dp"
                    android:layout_gravity="center_horizontal|top"
                    android:layout_margin="@dimen/margin_8dp"
                    android:background="@null"
                    android:gravity="top"
                    android:hint="添加描述~"
                    android:maxLength="120"
                    android:textColor="@color/share_text_color"
                    android:textCursorDrawable="@drawable/main_edit_cursor_bg"/>
            </android.support.design.widget.TextInputLayout>

            <TextView
                android:id="@+id/save_activity_tv_left_num"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="bottom|right"
                android:layout_marginBottom="@dimen/margin_20dp"
                android:layout_marginRight="@dimen/margin_20dp"
                android:text="还能输入120字"
                android:textColor="@color/grey"
                android:textStyle="bold"/>

        </FrameLayout>

        <LinearLayout
            android:id="@+id/linear_share"
            android:layout_width="match_parent"
            android:layout_height="@dimen/height_60dp"
            android:layout_alignParentBottom="true"
            android:background="@color/colorPrimary"
            android:orientation="vertical">

            <!--留意这个ImageButton的Id-->
            <ImageButton
                android:id="@+id/share_btn_share"
                android:layout_width="@dimen/width_50dp"
                android:layout_height="match_parent"
                android:layout_gravity="center_horizontal"
                android:background="@null"
                android:scaleType="fitCenter"
                android:src="@mipmap/title_button_share_bg"/>
        </LinearLayout>

</RelativeLayout>

点击失效的是ID为share_btn_share的ImageButton,正常看这个页面没有任何问题,ImageButton按照正常的setOnClickListener却无法响应点击,注意顶部是一个自定义的TitleView的符合控件,实现Toolbar的作用.内部也有ImageButton,在我重命名这个TitleView的ImageButton的时候,我发现上面布局里的ImageButton在Activity里findViewById的id也被修改了!这说明TitleView内部的ImageButton和布局里的ImageButton的Id重复了,导致Android Studio无法准确找到响应点击的ImageButton

转载于:https://my.oschina.net/lengwei/blog/687506

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值