gpt4 book ai didi

android - float 按钮不显示阴影

转载 作者:行者123 更新时间:2023-11-29 02:40:34 25 4
gpt4 key购买 nike

我正在为 float 按钮使用矢量可绘制对象。我想要在按钮下方增加灰色阴影。当我在 xml 中预览它时,它会显示阴影,但当我运行该应用程序时,它不会在设备中显示阴影。它发生的任何原因。下面的代码和屏幕截图:

<android.support.design.widget.FloatingActionButton
android:id="@+id/fab_add_cg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"
app:elevation="6dp"
app:borderWidth="0dp"
app:backgroundTint="@color/blue_4a90e2"
app:srcCompat="@drawable/add_fab"/>

矢量

<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="26dp"
android:height="24dp"
android:viewportWidth="26"
android:viewportHeight="24">

<group
android:translateX="-313.000000"
android:translateY="-550.000000">
<group
android:translateX="295.000000"
android:translateY="532.000000">
<group
android:translateX="18.000000"
android:translateY="18.000000">
<group
android:translateX="7.000000"
android:translateY="5.000000">
<path
android:fillColor="#FFFFFF"
android:fillType="evenOdd"
android:strokeWidth="1"
android:pathData="M 19 11 L 13 11 L 13 5 L 11 5 L 11 11 L 5 11 L 5 13 L 11 13 L 11 19 L 13 19 L 13 13 L 19 13 Z" />
</group>
<path
android:fillColor="#FFFFFF"
android:fillType="evenOdd"
android:strokeWidth="1"
android:pathData="M13.4558738,12.2931068 C15.3663592,11.1301456 16.6121845,9.05378641
16.6121845,6.645 C16.6123786,2.99019417 13.6219903,0 9.96737864,0 C6.31276699,0
3.32237864,2.99019417 3.32237864,6.645 C3.32237864,9.05378641
4.56839806,11.1303398 6.47868932,12.2931068 C3.15631068,13.538932
0.664466019,16.4462621 0,19.9347573 L1.66131068,19.9347573 C2.49184466,16.113835
5.89747573,13.2898058 9.96737864,13.2898058 C14.0372816,13.2898058
17.4429126,16.113835 18.2734951,19.9347573 L19.9347573,19.9347573
C19.2703398,16.3630097 16.7784951,13.4558738 13.4558738,12.2931068 Z
M4.98368932,6.645 C4.98368932,3.90398058 7.22635922,1.66131068
9.96737864,1.66131068 C12.7083981,1.66131068 14.951068,3.90398058
14.951068,6.645 C14.951068,9.38601942 12.7083981,11.6286893
9.96737864,11.6286893 C7.22635922,11.6286893 4.98368932,9.38601942
4.98368932,6.645 Z" />
</group>
</group>
</group>
</vector>

当我预览时: enter image description here

当我运行时: enter image description here

完整的布局代码:

<FrameLayout 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="@android:color/white"
android:orientation="vertical"
tools:context="com.fragment">

<LinearLayout
android:id="@+id/ll_cg_data"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:visibility="gone">

<android.support.v7.widget.RecyclerView
android:id="@+id/rv_"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:scrollbars="none" />

<LinearLayout
android:id="@+id/ll"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="@dimen/activity_margin_half"
android:orientation="vertical">

<com.lifeontrack.utils.RobotoTextView
android:id="@+id/tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="@string/good"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@color/grey_464646_85"
app:font="Roboto-Medium.ttf" />

<com.lifeontrack.utils.RobotoButton
android:id="@+id/btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_margin="@dimen/activity_margin_half"
android:background="@color/blue_4a90e2"
android:paddingLeft="10dp"
android:paddingTop="5dp"
android:text="@string/add"
android:textAllCaps="true"
android:textColor="@color/white"
android:textSize="16sp"
app:font="Roboto-Medium.ttf" />
</LinearLayout>

</LinearLayout>

<LinearLayout
android:id="@+id/ll_cg_no_data"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:visibility="gone">

<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="0.7"
android:background="@color/blue_eaeff4">

<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/_no" />
</RelativeLayout>

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".3"
android:paddingBottom="@dimen/activity_horizontal_margin">

<com.lifeontrack.utils.RobotoTextView
android:id="@+id/txt_good_cg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_margin="@dimen/activity_horizontal_margin"
android:gravity="center_horizontal"
android:text="@string/good"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="@android:color/black"
app:font="Roboto-Regular.ttf" />

<com.lifeontrack.utils.RobotoButton
android:id="@+id/btn_add_cg"
style="?android:textAppearanceButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_margin="@dimen/activity_margin_half"
android:background="@drawable/outline_blue_btn"
android:text="@string/add"
android:textAllCaps="true"
android:textColor="@color/dashboard_icon"
android:textStyle="bold"
app:font="Roboto-Medium.ttf" />
</RelativeLayout>
</LinearLayout>

<com.lifeontrack.utils.RobotoTextView
android:id="@+id/txt_no_records"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/no_records_found"
android:visibility="gone" />

<android.support.design.widget.FloatingActionButton
android:id="@+id/fab_add_cg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_centerHorizontal="true"
app:rippleColor="@android:color/white"
app:pressedTranslationZ="12dp"
android:layout_margin="@dimen/fab_margin"
app:elevation="12dp"
app:borderWidth="0dp"
app:backgroundTint="@color/blue_4a90e2"
app:srcCompat="@drawable/add_fab"/>

</FrameLayout>

最佳答案

使用 CoordinatorLayout获取新资源的所有效果。不要忘记添加这一行:xmlns:app="http://schemas.android.com/apk/res-auto"如果您使用 <include /> 将您的内容添加到主布局中会更好

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">

<include layout="@layout/content" />

<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_marginEnd="16dp"
android:layout_marginBottom="16dp"
app:elevation="6dp"
app:borderWidth="0dp"
app:srcCompat="@drawable/add_fab"
app:backgroundTint="#4a90e2"/>

</android.support.design.widget.CoordinatorLayout>

关于android - float 按钮不显示阴影,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44451281/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com