简体   繁体   English

Android Studio:浮动操作按钮:高程有效,但不能正常工作

[英]Android Studio: Floating Action Button: elevation works, but not as it should

I need Circle ImageView with Shadow(elevation) on version >=16, i decided to try FAB. 我需要版本> = 16的带有Shadow(elevation)的Circle ImageView,我决定尝试使用FAB。

The problem: If fabsize - normal 问题: 如果fabsize-正常

If you choose fabCustomSize(75dp)>fabsize(normal) - working, but image are to small: fabcustomsize 75dp 如果选择fabCustomSize(75dp)> fabsize(normal)-有效,但图像很小: fabcustomsize 75dp

XML: XML:

<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/colorBlueLightLight"
    tools:context=".MainActivity">

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:orientation="horizontal">

        <android.support.design.widget.FloatingActionButton
            android:id="@+id/floatingActionButton"
            android:layout_width="80dp"
            android:layout_height="80dp"
            android:layout_weight="1"
            android:clickable="true"
            app:backgroundTint="#C4C4C4"
            app:borderWidth="0dp"
            app:elevation="4dp"
            app:fabCustomSize="75dp"
            app:fabSize="normal"
            app:rippleColor="#25FAFAFA"
            app:srcCompat="@drawable/mute_2"
            app:useCompatPadding="false" />
    </LinearLayout>

The other two buttons have the same code 另外两个按钮具有相同的代码

Solution 1 解决方案1

This solution works only for AndroidX, you can read @answer for migrating to AndroidX. 此解决方案仅适用于AndroidX,您可以阅读@answer迁移到AndroidX。 Use app:maxImageSize="50dp" in your fab. 在您的晶圆厂中使用app:maxImageSize="50dp"

产量

Solution 2 解决方案2

If you don't want to use AndroidX for now, then put this dimen in your dimens.xml 如果您暂时不想使用AndroidX,请dimens.xml放入您的dimens.xml

<dimen name="design_fab_image_size" tools:override="true">70dp</dimen>

Update 更新

Don't set android:layout_width and android:layout_height if you are setting app:fabCustomSize . 如果要设置app:fabCustomSize不要设置android:layout_widthandroid:layout_height Then your fab will not be like square. 那么您的晶圆厂将不会像正方形。

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

相关问题 提升浮动操作按钮不起作用 - Elevation for Floating action button is not working Android支持设计浮动操作按钮高程对于白色以外的颜色不可见 - Android support design floating action button elevation not visible for colors other than white Android 5.0 android:提升适用于View,但不适用于Button? - Android 5.0 android:elevation Works for View, but not Button? 浮动动作按钮android - Floating Action Button android 浮动操作按钮不显示 Android Studio 中的源图像..? - Floating Action Button not display the source Image in Android Studio..? Android Studio如何调整浮动动作按钮的图像源 - Android Studio how to adjust the image source of a floating action button 浮动操作按钮在Android Studio中的Google Map上不可见 - Floating action button not visible over the Google Map in Android Studio Android Studio 1.5.1。渲染错误(浮动操作按钮) - Android Studio 1.5.1.Rendering error (Floating action button) Android Studio - 浮动操作按钮在 ViewPager 初始化中不起作用 - Android Studio - Floating Action Button not working on ViewPager Initialization 浮动操作按钮 (FAB) 默认以矩形显示 - Android Studio - Floating Action Button (FAB) appears in rectangle shape by default - Android Studio
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM