在应用程序兼容性和设计库中没有阴影 [英] No shadow in appcompat and design library

查看:183
本文介绍了在应用程序兼容性和设计库中没有阴影的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是有我的应用程序没有影子。我使用应用程序兼容性Libary 设计库。在preVIEW(机器人工作室)有影子,但我不能在我的手机上的应用程序看到的。

My problem is there isn't shadow in my app. I am using AppCompat Libary, and Design Library. In preview (android studio) there is shadow, BUT I can't see in my app on the phone.

下面是我的布局code

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

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            android:theme="@style/ThemeToolbar" />
    </android.support.design.widget.AppBarLayout>

    <android.support.v4.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">


            <android.support.v7.widget.CardView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="@dimen/cardViewMarginTopBottom"
                android:layout_marginLeft="@dimen/cardViewMarginSlide"
                android:layout_marginRight="@dimen/cardViewMarginSlide"
                android:layout_marginTop="@dimen/cardViewMarginTopBottom"
                android:padding="@dimen/cards_padding"
                app:cardBackgroundColor="@color/icons"
                app:cardCornerRadius="@dimen/cardCornerRadius"
                app:cardElevation="@dimen/cardElevation"
                app:cardMaxElevation="@dimen/cardMaxElevation">

                <LinearLayout
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:layout_margin="@dimen/cards_margin"
                    android:orientation="vertical">


                    <TextView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_margin="@dimen/cards_text_margin"
                        android:lineSpacingMultiplier="1.2"
                        android:text="Data"
                        android:textColor="@color/primary"
                        android:textSize="@dimen/text_big" />


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

                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_margin="@dimen/cards_text_margin"
                            android:lineSpacingMultiplier="1.2"
                            android:text="X: "
                            android:textColor="@color/primary_text"
                            android:textSize="@dimen/text_small"
                            android:textStyle="bold" />

                        <TextView
                            android:id="@+id/textViewFragmentHome1"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_margin="@dimen/cards_text_margin"
                            android:lineSpacingMultiplier="1.2"
                            android:textColor="@color/primary_text"
                            android:textSize="@dimen/text_small" />
                    </LinearLayout>

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

                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_margin="@dimen/cards_text_margin"
                            android:lineSpacingMultiplier="1.2"
                            android:text="Y: "
                            android:textColor="@color/primary_text"
                            android:textSize="@dimen/text_small"
                            android:textStyle="bold" />

                        <TextView
                            android:id="@+id/textViewFragmentHome2"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_margin="@dimen/cards_text_margin"
                            android:lineSpacingMultiplier="1.2"
                            android:textColor="@color/primary_text"
                            android:textSize="@dimen/text_small" />
                    </LinearLayout>

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

                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_margin="@dimen/cards_text_margin"
                            android:lineSpacingMultiplier="1.2"
                            android:text="Z: "
                            android:textColor="@color/primary_text"
                            android:textSize="@dimen/text_small"
                            android:textStyle="bold" />

                        <TextView
                            android:id="@+id/textViewFragmentHome3"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_margin="@dimen/cards_text_margin"
                            android:lineSpacingMultiplier="1.2"
                            android:textColor="@color/primary_text"
                            android:textSize="@dimen/text_small" />
                    </LinearLayout>

                </LinearLayout>

            </android.support.v7.widget.CardView>

            <android.support.v7.widget.CardView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="@dimen/cardViewMarginTopBottom"
                android:layout_marginLeft="@dimen/cardViewMarginSlide"
                android:layout_marginRight="@dimen/cardViewMarginSlide"
                android:layout_marginTop="@dimen/cardViewMarginTopBottom"
                android:padding="@dimen/cards_padding"
                app:cardBackgroundColor="@color/icons"
                app:cardCornerRadius="@dimen/cardCornerRadius"
                app:cardElevation="@dimen/cardElevation"
                app:cardMaxElevation="@dimen/cardMaxElevation">

                <com.github.mikephil.charting.charts.LineChart
                    android:id="@+id/lineChartFragmentHome1"
                    android:layout_width="match_parent"
                    android:layout_height="250dp" />

            </android.support.v7.widget.CardView>


            <android.support.v7.widget.CardView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="@dimen/cardViewMarginTopBottom"
                android:layout_marginLeft="@dimen/cardViewMarginSlide"
                android:layout_marginRight="@dimen/cardViewMarginSlide"
                android:layout_marginTop="@dimen/cardViewMarginTopBottom"
                android:padding="@dimen/cards_padding"
                app:cardBackgroundColor="@color/icons"
                app:cardCornerRadius="@dimen/cardCornerRadius"
                app:cardElevation="@dimen/cardElevation"
                app:cardMaxElevation="@dimen/cardMaxElevation"
                app:cardUseCompatPadding="true">

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical">

                    <android.support.v7.widget.AppCompatCheckBox
                        android:id="@+id/checkboxFragmentHome1"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_margin="@dimen/cards_text_margin"
                        android:checked="true"
                        android:text="Show X line"
                        android:textSize="@dimen/text_med" />

                    <android.support.v7.widget.AppCompatCheckBox
                        android:id="@+id/checkboxFragmentHome2"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_margin="@dimen/cards_text_margin"
                        android:checked="true"
                        android:text="Show Y line"
                        android:textSize="@dimen/text_med" />

                    <android.support.v7.widget.AppCompatCheckBox
                        android:id="@+id/checkboxFragmentHome3"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_margin="@dimen/cards_text_margin"
                        android:checked="true"
                        android:text="Show Z line"
                        android:textSize="@dimen/text_med" />

                </LinearLayout>
            </android.support.v7.widget.CardView>


            <android.support.v7.widget.CardView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="@dimen/cardViewMarginTopBottom"
                android:layout_marginLeft="@dimen/cardViewMarginSlide"
                android:layout_marginRight="@dimen/cardViewMarginSlide"
                android:layout_marginTop="@dimen/cardViewMarginTopBottom"
                android:padding="@dimen/cards_padding"
                app:cardBackgroundColor="@color/icons"
                app:cardCornerRadius="@dimen/cardCornerRadius"
                app:cardElevation="@dimen/cardElevation"
                app:cardMaxElevation="@dimen/cardMaxElevation">

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical">

                    <android.support.v7.widget.SwitchCompat
                        android:id="@+id/switchFragmentHome1"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_margin="@dimen/cards_text_margin"
                        android:checked="false"
                        android:text="Show X axis lines number"
                        android:textSize="@dimen/text_med" />

                    <android.support.v7.widget.SwitchCompat
                        android:id="@+id/switchFragmentHome2"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_margin="@dimen/cards_text_margin"
                        android:checked="false"
                        android:text="Just do it slowly.."
                        android:textSize="@dimen/text_med" />

                </LinearLayout>
            </android.support.v7.widget.CardView>

        </LinearLayout>
    </android.support.v4.widget.NestedScrollView>

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fabFragmentHome"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="end|bottom"
        android:layout_margin="@dimen/floatingActionButtonMargin"
        android:scaleType="center"
        android:src="@drawable/ic_av_pause"
        app:layout_behavior="com.eternal.arcanus.accelerometer.helpers.FloatingButtonScroll" />
</android.support.design.widget.CoordinatorLayout>

下面是Android的工作室preVIEW:

Here is android studio preview:

在这里输入的形象描述

和手机显示的:

在这里输入的形象描述

我做错了什么?

推荐答案

有没有默认的阴影不幸的是(或者至少尽可能靠近我可以告诉大家,我很高兴得到纠正)。然而,在你的情况,至少有一个解决办法。

There is no default shadow unfortunately (or at least as near as I can tell, I am happy to be corrected). However, in your case, there is at least one workaround.

首先,创建一个绘制 XML 文件重新present你的影子(即 app_bar_shadow.xml

First, create a drawable xml file to represent your shadow (i.e. app_bar_shadow.xml):

<shape
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">    
    <gradient
        android:startColor="#02444444"
        android:endColor="#33111111"
        android:angle="90"/>
</shape>

然后将其添加到您的布局,并为其分配一个滚动行为。将其放置下你在你的布局 NestedScrollView 文件:

Then add it to your layout, and assign it a scrolling behaviour. Place it just underneath your NestedScrollView in your layout file:

<View
    android:layout_width="match_parent"
    android:layout_height="4dp"
    android:id="@+id/app_bar_shadow"
    android:layout_gravity="top"
    android:background="@drawable/app_bar_shadow"
    app:layout_behavior="@string/appbar_scrolling_view_behavior" />

这篇关于在应用程序兼容性和设计库中没有阴影的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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