浮动操作按钮向后兼容性问题

问题描述:

所以我正在与一些浮动的操作按钮的应用程序,但在我的情况下,他们被固定在视图中,但我喜欢他们看起来浮动操作按钮向后兼容性问题

不管怎样的方式,似乎对旧的API如果冻豆它有问题显示为附加图像,但它kitkat和后来它完美地显示,任何想法如何解决这个问题?

xml文件

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 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:orientation="vertical" 
    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="ly.bsagar.libyanaguid.services"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="@dimen/fab_margin" 
     android:layout_marginRight="@dimen/fab_margin" 
     android:layout_weight="1" 
     android:gravity="center"> 

     <TextView 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="2" 
      android:gravity="center" 
      android:text="@string/internetService" 
      android:textSize="@dimen/text_size_large" /> 

     <ImageView 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_weight="1" 
      android:src="@drawable/ic_public_black_24dp" /> 
    </LinearLayout> 

    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="0dp" 
     android:layout_gravity="center" 
     android:layout_marginLeft="@dimen/fab_margin" 
     android:layout_marginRight="@dimen/fab_margin" 
     android:layout_weight="2" 
     android:gravity="center"> 

     <android.support.design.widget.FloatingActionButton 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_gravity="center" 
      android:layout_margin="@dimen/fab_margin" 
      android:layout_weight="1" 
      android:onClick="ActInternet" 
      android:src="@drawable/ic_done_black_24dp" /> 

     <android.support.design.widget.FloatingActionButton 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_gravity="center" 
      android:layout_margin="@dimen/fab_margin" 
      android:layout_weight="1" 
      android:onClick="DisInternet" 
      android:src="@drawable/ic_clear_black_24dp" /> 

     <android.support.design.widget.FloatingActionButton 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_gravity="center" 
      android:layout_margin="@dimen/fab_margin" 
      android:layout_weight="1" 
      android:onClick="getSetting" 
      android:src="@drawable/ic_settings_black_24dp" /> 
    </LinearLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="@dimen/activity_horizontal_margin" 
     android:layout_marginRight="@dimen/activity_horizontal_margin" 
     android:layout_marginTop="@dimen/fab_margin" 
     android:layout_weight="1" 
     android:gravity="center"> 

     <TextView 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="2" 
      android:gravity="center" 
      android:text="@string/callWaiting" 
      android:textSize="@dimen/text_size_large" /> 

     <ImageView 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_weight="1" 
      android:src="@drawable/ic_phone_paused_black_24dp" /> 
    </LinearLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_marginLeft="@dimen/fab_margin" 
     android:layout_marginRight="@dimen/fab_margin" 
     android:layout_weight="2" 
     android:gravity="center"> 

     <android.support.design.widget.FloatingActionButton 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_gravity="center" 
      android:layout_margin="@dimen/fab_margin" 
      android:layout_weight="1" 
      android:onClick="actwaiting" 
      android:src="@drawable/ic_done_black_24dp" /> 

     <android.support.design.widget.FloatingActionButton 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_gravity="center" 
      android:layout_margin="@dimen/fab_margin" 
      android:layout_weight="1" 
      android:onClick="deactwaiting" 
      android:src="@drawable/ic_clear_black_24dp" /> 

     <android.support.design.widget.FloatingActionButton 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_gravity="center" 
      android:layout_margin="@dimen/fab_margin" 
      android:layout_weight="1" 
      android:onClick="statuswaiting" 
      android:src="@drawable/ic_error_outline_black_24dp" /> 
    </LinearLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="@dimen/fab_margin" 
     android:layout_marginRight="@dimen/fab_margin" 
     android:layout_weight="1" 
     android:gravity="center"> 

     <TextView 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="2" 
      android:gravity="center" 
      android:text="@string/missedCallNotification" 
      android:textSize="@dimen/text_size_medium" /> 

     <ImageView 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_weight="1" 
      android:src="@drawable/ic_phone_missed_black_24dp" /> 
    </LinearLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_marginLeft="@dimen/fab_margin" 
     android:layout_marginRight="@dimen/fab_margin" 
     android:layout_weight="2" 
     android:gravity="center"> 

     <android.support.design.widget.FloatingActionButton 
      android:layout_width="wrap_content" 
      android:layout_height="match_parent" 
      android:layout_gravity="center" 
      android:layout_margin="@dimen/fab_margin" 
      android:layout_weight="1" 
      android:background="@color/colorAccent" 
      android:onClick="actmissed" 
      android:src="@drawable/ic_done_black_24dp" /> 

     <TextView 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_weight="1" /> 

     <android.support.design.widget.FloatingActionButton 
      android:layout_width="wrap_content" 
      android:layout_height="match_parent" 
      android:layout_gravity="center" 
      android:layout_margin="@dimen/fab_margin" 
      android:layout_weight="1" 
      android:onClick="deactmissed" 
      android:src="@drawable/ic_clear_black_24dp" /> 

    </LinearLayout> 

</LinearLayout> 

bad view

good view (ignore that square, I was testing something

在此先感谢

+0

设置高度对晶圆厂WRAP_CONTENT。去除重量。 –

好了,我不知道问题,您正面临什么,但它可能与落后的问题这种观点的兼容性。

你可以试试这个aditional的免费Floating Action Button library for Android 它有许多自定义和要求SDK版本9和更高

enter image description here

Full Demo Video

此外,如果可能的降级(如果你使用较新的版本)谷歌的设计档案文件build.gradle档案

compile 'com.android.support:design:22.2.0' 

更多的解决方案,你会发现这里:

How to create a floating action button (FAB) in android, using AppCompat v21?

Floating Action Button for lower version

希望它能帮助

+0

我想了解材料设计的最佳实践。我有一个可以运行的应用程序,但某些材料组件不适用于运行各种API的不同设备。你有推荐的教程/资源吗? – tccpg288