我的问题是我的应用程序中没有阴影。我正在使用AppCompat Libary
和Design Library
。在预览版(Android Studio)中,有阴影,但我在手机上的应用程序中看不到。
这是我的layout 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 studio预览:
电话显示以下内容:
我做错了什么?
不幸的是,没有默认阴影(或者至少我可以告诉我,我很高兴得到纠正)。但是,根据您的情况,至少有一种解决方法。
首先,创建一个drawable
xml
文件来表示您的阴影(即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>
然后将其添加到您的中layout
,并为其分配滚动行为。将其NestedScrollView
放在layout
文件的下方:
<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" />
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句