简体   繁体   English

Android:图层列表浮动操作按钮-暂停和恢复应用后,按钮阴影看起来有所不同

[英]Android: Layer List Floating Action Button - Button shadow looks different after app is paused and resumed

Apologies in advance if this question has already been asked somewhere on this site. 如果已经在此站点的某个地方提出了此问题,请提前道歉。 I just wasn't sure how to word it in the search bar. 我只是不确定如何在搜索栏中输入文字。 I tried though. 我试过了

So basically, I know Android Studio will allow you to create a floating action button without the extra effort now but I'm just seeing if I can make one without it. 因此,基本上,我知道Android Studio现在允许您无需任何额外的努力即可创建一个浮动动作按钮,但是我只是在看看是否可以不用它来制作一个。 I've done it with some help I got from another question here but for some reason, when I start the app, the Floating Action Button's shadow looks like this: 我已经从另一个问题中得到了一些帮助,但是由于某种原因,当我启动应用程序时,“浮动操作按钮”的阴影看起来像这样:

在此处输入图片说明

But when I exit and return before it is removed from memory (either exiting and returning a few seconds later or pausing the app and resuming), the shadow turns into this: 但是,当我退出并返回之前,将其从内存中删除(几秒钟后退出并返回,或者暂停应用并恢复),阴影变成了这样:

在此处输入图片说明

This is my circle.xml file: 这是我的circle.xml文件:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

<item android:top="8px">
    <layer-list>
        <item>
            <shape android:shape="oval">
                <solid android:color="#08000000"/>
                <padding
                    android:bottom="3px"
                    android:left="3px"
                    android:right="3px"
                    android:top="3px"
                    />
            </shape>
        </item>
        <item>
            <shape android:shape="oval">
                <solid android:color="#09000000"/>
                <padding
                    android:bottom="2px"
                    android:left="2px"
                    android:right="2px"
                    android:top="2px"
                    />
            </shape>
        </item>
        <item>
            <shape android:shape="oval">
                <solid android:color="#10000000"/>
                <padding
                    android:bottom="2px"
                    android:left="2px"
                    android:right="2px"
                    android:top="2px"
                    />
            </shape>
        </item>
        <item>
            <shape android:shape="oval">
                <solid android:color="#11000000"/>
                <padding
                    android:bottom="1px"
                    android:left="1px"
                    android:right="1px"
                    android:top="1px"
                    />
            </shape>
        </item>
        <item>
            <shape android:shape="oval">
                <solid android:color="#12000000"/>
                <padding
                    android:bottom="1px"
                    android:left="1px"
                    android:right="1px"
                    android:top="1px"
                    />
            </shape>
        </item>
        <item>
            <shape android:shape="oval">
                <solid android:color="#13000000"/>
                <padding
                    android:bottom="1px"
                    android:left="1px"
                    android:right="1px"
                    android:top="1px"
                    />
            </shape>
        </item>
        <item>
            <shape android:shape="oval">
                <solid android:color="#14000000"/>
                <padding
                    android:bottom="1px"
                    android:left="1px"
                    android:right="1px"
                    android:top="1px"
                    />
            </shape>
        </item>
        <item>
            <shape android:shape="oval">
                <solid android:color="#15000000"/>
                <padding
                    android:bottom="1px"
                    android:left="1px"
                    android:right="1px"
                    android:top="1px"
                    />
            </shape>
        </item>

    </layer-list>
</item>

<item >
    <shape android:shape="oval">
        <solid android:color="#FFBB00" />
    </shape>
</item>


</layer-list>

And this is how my activity_main.xml : 这就是我的activity_main.xml的方式

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"

    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.myname.testapp.MainActivity">


    <ImageButton
        android:layout_margin="15dp"
        android:layout_width="70dp"
        android:layout_height="70dp"
        android:background="@drawable/circle"
        android:id="@+id/fab_button"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true" />

   <ListView
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:id="@+id/ResultsListView"
       android:layout_alignParentTop="true"
       android:layout_alignParentLeft="true"
       android:layout_alignParentStart="true" />

</RelativeLayout>

Any idea what is going on? 知道发生了什么吗? I'm still relatively new to Android App development so sorry if this happens to be a minor error. 我对Android App开发还是比较陌生,所以如果这是个小错误,请对不起。 I'm still not sure what is going on. 我仍然不确定发生了什么。 Any bit of help will be greatly appreciated. 任何帮助将不胜感激。 Thank you very much. 非常感谢你。

change your circle.xml to this: 将您的circle.xml更改为:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item >
        <shape android:shape="oval">
            <solid android:color="#FFBB00" />
        </shape>
    </item>
</layer-list>

and add this line 并添加此行

android:elevation="5dp" android:elevation =“ 5dp”

to image button. 图像按钮。

more info Defining Shadows and Clipping Views 更多信息定义阴影和裁剪视图

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM