在SDK Manager的Android 5.0示例中,有ElevationBasic示例.它显示了两个View对象:圆形和方形.圆圈android:elevation设置为30dp:
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright 2014 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF …Run Code Online (Sandbox Code Playgroud) 首先,我知道之前已经问过这个问题,但之前没有得到回答.我希望有人能给我一个答案.
在我的应用程序中,我使用Appcompat_v7(API 21)中的工具栏.这是我的代码:
<android.support.v7.widget.Toolbar
style="@style/DarkActionbarStyle"
android:id="@+id/toolBar"
android:layout_width="match_parent"
android:layout_height="@dimen/actionbar_height" />
Run Code Online (Sandbox Code Playgroud)
这是我使用的ToolBar样式:
<style name="DarkActionbarStyle" parent="@style/Widget.AppCompat.Toolbar">
<item name="android:background">?attr/colorPrimary</item>
<item name="titleTextAppearance">@style/ActionBarTitle</item>
<item name="android:elevation">2dp</item>
<item name="popupTheme">@style/ThemeOverlay.AppCompat.Light</item>
<item name="theme">@style/ThemeActionBarDark</item>
</style>
<style name="ThemeActionBarDark" parent="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<item name="actionBarItemBackground">@drawable/btn_dark_orange</item>
<item name="selectableItemBackground">@drawable/btn_dark_orange</item>
</style>
Run Code Online (Sandbox Code Playgroud)
问题是,提升前棒棒糖不起作用.所以我的问题是:棒棒糖设备上的工具栏下是否有阴影?
android toolbar shadow android-appcompat android-5.0-lollipop
在寻找解决方案后,我找不到任何解决我的问题的方法.
我有一些高度会在我的应用程序的很大一部分上产生阴影.
但在某个特定的地方,我无法使其发挥作用.
(这是我在下面的图片上放箭头的地方)
工具栏下方的白色区域Fragment显示aLinearLayout
布局:
<LinearLayout
android:id="@+id/panelAddress"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/button_flat_white"
android:elevation="10dp"
android:orientation="vertical"
android:padding="20dp"
>
//some content
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
片段的父母:
<android.support.v4.widget.DrawerLayout
android:id="@+id/drawerLayout"
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"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include
android:id="@+id/custom_toolbar"
layout="@layout/toolbar"/>
<RelativeLayout
android:id="@+id/mapLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment
android:id="@+id/map"
class="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<FrameLayout
android:id="@+id/fragment_container_top"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
/>
<FrameLayout
android:id="@+id/fragment_container_bottom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"/>
</RelativeLayout>
</LinearLayout>
</android.support.v4.widget.DrawerLayout>
Run Code Online (Sandbox Code Playgroud)
你知道为什么我没有升高吗?
我想在最新的Android Lollipop预览版中使用elevation属性.我将targetSdk设置为21,将主题设置为Material.接下来,我将一个背景形状添加到TextView并将高程设置为8dp,但TextView没有显示任何阴影的迹象.这是在运行棒棒糖预览的Nexus7上.还有什么我需要考虑的吗?
这是布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/rect"
android:text="hallo world"
android:padding="8dp"
android:elevation="8dp" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
这是背景可绘制的:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#7d0073ff" />
<corners android:radius="16dp" />
</shape>
Run Code Online (Sandbox Code Playgroud)
这是TextView:

我想在圆形imageView周围添加阴影.这是我的代码.我想做这样的形象

activity_main.xml中
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<RelativeLayout
android:id="@+id/layoutTop"
android:layout_width="match_parent"
android:layout_height="200dp"
android:background="#355482" >
</RelativeLayout>
<RelativeLayout
android:id="@+id/layoutBottom"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_alignParentBottom="true"
android:layout_below="@+id/layoutTop"
android:background="@drawable/loading" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="113dp"
android:text="Profile"
android:textColor="#355482"
android:textSize="20dp"
android:textStyle="bold" />
</RelativeLayout>
<ImageView
android:id="@+id/overlapImage"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="132dp"
android:adjustViewBounds="true"
android:background="@drawable/round_image"
android:src="@drawable/ic_launcher" />
Run Code Online (Sandbox Code Playgroud)
这是round_image.xml:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid android:color="#ffffff" />
<corners android:radius="2dp"/>
<size
android:height="80dp"
android:width="80dp" />
<padding
android:bottom="0dp"
android:left="0dp"
android:right="0dp"
android:top="0dp" />
</shape>
Run Code Online (Sandbox Code Playgroud)
我尝试了一些阴影效果的代码,但它不起作用.
我正在使用android中的recyclelerview进行网格布局.网格占据屏幕的一部分并具有阴影.为了获得所需的阴影效果,我使用的是12 dp的高程值.但它似乎不起作用,因为我看不到网格的任何高程(阴影).为什么会这样?recyclerview不支持提升吗?
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:id="@+id/activity_grid_layout"
android:background="@drawable/gradient"
android:layout_height="match_parent"
tools:context="com.mindhive.mindhive.activities.GridActivity">
<android.support.v7.widget.RecyclerView
android:id="@+id/grid_recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="110dp"
android:layout_marginLeft="15dp"
android:layout_marginTop="80dp"
android:background="@color/transparent"
android:elevation="12dp"
android:scrollIndicators="none"
android:scrollbars="none"
android:padding="0dp" />
<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/grid_recycler_view"
android:layout_alignStart="@+id/grid_recycler_view"
android:layout_marginBottom="-18dp"
android:layout_marginStart="67dp"
android:src="@drawable/main_filter"
android:elevation="1dp" />
......
Run Code Online (Sandbox Code Playgroud) android recycler-adapter android-recyclerview recyclerview-layout
正如标题所述,我正在尝试将一个CardView放在ScrollView中,但是CardView高程阴影正在被它的父母关闭...
这是布局XML:
<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"
tools:context=".TestScrollViewActivity">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="128dp"
android:background="?colorPrimary"
android:gravity="bottom"
android:minHeight="?actionBarSize"/>
<ScrollView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:clipToPadding="false"
android:paddingBottom="40dp"
android:paddingTop="60dp">
<android.support.v7.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:elevation="4dp"
app:cardBackgroundColor="@android:color/white"
app:cardCornerRadius="0dp">
<LinearLayout
android:layout_width="400dp"
android:layout_height="600dp"
android:orientation="vertical">
</LinearLayout>
</android.support.v7.widget.CardView>
</ScrollView>
</FrameLayout>
Run Code Online (Sandbox Code Playgroud)
我找到的唯一解决方法是向父ScrollView添加填充或向子CardView添加边距...
有没有选项可以防止这种情况发生而不使用填充/边距?
谢谢.
编辑:
这就是布局在没有在父滚动视图上设置填充的情况下的样子,因为可以看到,左右阴影被切断:

现在,如果将填充添加到父滚动视图侧,则可以正确绘制阴影,如下所示:

所以,我的主要问题是这是实现这一目标的唯一方法吗?或者父视图上有一个标记或配置,可以正确绘制它的子视图?
在Material Design指南中,Google推出了一种新的按钮样式,即FAB Button.我找到了如何制作它的说明,但是添加阴影时遇到了麻烦.怎么能实现这一目标?
android button shadow floating-action-button android-5.0-lollipop
我最近正在使用动画,并且FrameLayout由于奇怪的原因没有正确显示其阴影时遇到了麻烦.
我找到了一个很好的答案,这对我很有帮助,但是有一个叫做的属性clipToPadding.答案可以在这里找到:Android"海拔"没有显示阴影
但是,我真的很想了解这个属性的用途.我去了Android的文档,其中指出:
如果填充不为零,则定义ViewGroup是否剪切其子节点并将任何EdgeEffect调整大小(但不剪切)到其填充.默认情况下,此属性设置为true.
我已经阅读了很多次,我在网上寻找了一些例子,但我真的找不到一些.我发现的唯一视觉效果与此ClipToPadding差异类似
我可以看到名单上的效果,但它如何影响,只有一个,当View在ViewGroup例如等.
如果有人可以提供一些关于这个属性的关键点以及如何使用一些例子,那将是很好的.
将我的代码删除到最小的例子:
activity_main.xml中
<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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">
<LinearLayout
android:id="@+id/main_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp">
<Button
android:id="@+id/my_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginLeft="20dp"
android:elevation="10dp"
android:translationZ="10dp"
android:background="@android:color/holo_green_light"
android:text="BUTTON"/>
</RelativeLayout>
</LinearLayout>
</ScrollView>
Run Code Online (Sandbox Code Playgroud)
我需要那种布局结构.
MainActivity.java
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
Run Code Online (Sandbox Code Playgroud)
在Android Studio设计器中可以看到阴影:
但是在运行时没有显示:
测试:
问题是我想在列表视图中显示像自定义视图一样的卡片视图。该视图在模拟器中显示良好,但在模拟器中未显示相同。
这是可以同时看到两个预览的图像的链接。
列表视图代码:
<?xml version="1.0" encoding="utf-8"?>
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/custom_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:divider="@android:color/transparent"
android:dividerHeight="10.0sp"
android:clipToPadding="false"
tools:listitem="@layout/listlayout">
</ListView>
Run Code Online (Sandbox Code Playgroud)
自定义视图代码:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:elevation="10dp">
<ImageView
android:layout_width="64dp"
android:layout_height="64dp"
android:id="@+id/productImage"
android:layout_gravity="center" />
<LinearLayout
android:orientation="vertical"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_marginLeft="5dp"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="@string/product_title"
android:id="@+id/title"
android:textStyle="bold" />
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="shortDescription"
android:textSize="@dimen/abc_text_size_body_1_material"
android:id="@+id/shortDescription" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="price"
android:id="@+id/price"
android:textAlignment="center"
android:gravity="center"
android:singleLine="true"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="newPrice"
android:singleLine="true"
android:id="@+id/newPrice"
android:autoText="false"
android:gravity="center" …Run Code Online (Sandbox Code Playgroud) 更新支持库后,我试图在导航抽屉上设置阴影,但由于某种原因,没有任何效果,我很困惑。
我遇到了这个问题,但它的解决方案是仅使用 setElevation ,这对我来说也不起作用:https://code.google.com/p/android/issues/detail ?id=184434
确实没有太多代码可发布,但以下是我所说的供参考:
int currentapiVersion = android.os.Build.VERSION.SDK_INT;
if (currentapiVersion >= android.os.Build.VERSION_CODES.LOLLIPOP) {
mDrawerLayout.setDrawerElevation(25f);
} else {
mDrawerLayout.setDrawerShadow(R.drawable.left_drawer_shadow, GravityCompat.START);
}
Run Code Online (Sandbox Code Playgroud)
我正在使用 ScrimInsetsFrameLayout 但这不应该导致问题 AFAIKT。
有任何想法吗?