点击时不要将按钮置于前台 [英] Don't bring button to foreground on click

查看:121
本文介绍了点击时不要将按钮置于前台的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

My app currently looks like below. Three Buttons in a RelativeLayout, the middle button has negative margin left and right to overlap the other two buttons.

问题:当我单击向左或向右按​​钮时,它到达前景一秒钟,并且与中间按钮重叠,这看起来非常难看.

Issue: When I click either the left or the right button, it gets to the foreground for a second and overlaps the middle button, which looks very ugly.

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

推荐答案

默认按钮具有被触摸时运行的动画,并使用的动画会更改android:elevationandroid:translateZ属性视图的.

The default button has animations that run when it's touched and uses a StateListAnimator to do this. The animations that elevate the button changes the android:elevation and android:translateZ properties of the view.

要防止这种情况发生动画,只需设置以下设置即可停止动画在此View上运行: android:stateListAnimator="@null"

To prevent this from animating, simply stop animations from running on this View by setting: android:stateListAnimator="@null"

这篇关于点击时不要将按钮置于前台的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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