android - 单击时不要将按钮置于前台

标签 android button android-relativelayout overlap z-order

我的应用目前如下所示。 RelativeLayout 中的三个 Button,中间按钮的左右负边距与其他两个按钮重叠。

问题:当我点击左侧或右侧按钮时,它会出现一秒钟并与中间按钮重叠,看起来非常难看。

enter image description here

enter image description here

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal">

        <Button
            android:id="@+id/voices"
            android:layout_width="160dp"
            android:layout_height="wrap_content"

            android:layout_gravity="center_vertical"

            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:onClick="clickVoices"
            android:background="#333"
            android:textColor="#fff"
            android:text="@string/main_voices" />

        <Button
            android:id="@+id/chat"
            android:layout_width="160dp"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:layout_alignParentRight="true"
            android:layout_alignParentTop="true"

            android:onClick="clickChat"
            android:background="#333"
            android:textColor="#fff"
            android:text="@string/main_chat" />

        <Button
            android:id="@+id/record"
            android:layout_width="60dp"
            android:layout_height="100dp"

            android:clickable="true"
            android:onClick="clickRecord"
            android:scaleType="centerInside"
            android:src="@drawable/record"
            android:text="Record"
            android:layout_toRightOf="@+id/voices"
            android:layout_toLeftOf="@+id/chat"
            android:layout_marginLeft="-20dp"
            android:layout_marginRight="-20dp"
            android:layout_marginTop="-30dp"
            android:background="@drawable/round_button"

            android:paddingTop="30dp"
            android:layout_marginBottom="10dp" />
    </RelativeLayout>

最佳答案

默认按钮具有在触摸时运行的动画,并使用 StateListAnimator去做这个。提升按钮的动画 changes the android:elevation and android:translateZ properties of the view .

要防止动画,只需通过设置停止动画在此 View 上运行: android:stateListAnimator="@null"

关于android - 单击时不要将按钮置于前台,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36425626/

相关文章:

android - RelativeLayout 问题

包含 RelativeLayout 的 android 移动 View

android - 保护安卓源代码

android - 我如何让 Robospice 将来自 Retrofit 和 OKHttp 的 200 响应以外的任何其他内容视为错误

c# - 如何定位窗口内的所有按钮?

javascript - 悬停选项,或 JavaScript

android - Kivy 应用程序在后台(无 Gui,服务)

android - 在 Android 中将 Cordova 与 Crosswalk 结合使用时使用自定义插件

css - 如何使用 CSS HTML 在同一区域显示单独的段落

android - 根据条件以编程方式修改 RelativeLayout