我已经使用L预览版玩了几天,有一件事似乎不起作用,那就是对于视图的
这是结果的截图:imgur.com/mqeq9vK
根据我设置的
编辑:似乎只有在
android:elevation
属性。当调用View.setElevation()
时它可以正常工作,但是它似乎忽略了XML属性。我使用的是Android Studio 0.8.2,并且将minSdkVersion
和targetSdkVersion
设置为'L'
,compileSdkVersion
设置为'android-L'
。buildToolsVersion
是"20.0.0"
。这里是一个无法正常工作的示例布局:<?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"
android:orientation="vertical">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_margin="10dp"
android:elevation="5dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="top"/>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_margin="10dp"
android:elevation="0dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="bottom"/>
</android.support.v7.widget.CardView>
</LinearLayout>
这是结果的截图:imgur.com/mqeq9vK
根据我设置的
android:elevation
,底部卡片应该平放在“地面”上,但实际上并没有。事实上,它看起来和顶部卡片的高度为5dp
的高度没有任何区别。这是已知问题吗?你能正常工作吗?编辑:似乎只有在
CardView
中才会出现这种情况,或者至少不是Buttons
的问题。在这个布局中,我用Button
替换了CardView
,即使阴影有点问题(已知的错误),你仍然可以看到高度的差异。<?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"
android:orientation="vertical">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:elevation="2dp"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:elevation="1dp"/>
</LinearLayout>
编辑 2: 目前基本确认这个问题只影响CardView
,android:elevation
在其他视图中正常工作。关于为什么会发生这种情况的详细解释,请查看已接受的答案。与此同时,我的解决方法是将CardView
替换为FrameLayout
,并将android:background
设置为可绘制项。以下是一个可用的卡片背景可绘制对象示例:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<solid android:color="#fff" />
</shape>
我也已将此问题报告为错误,请您收藏此问题,如果它对您有影响。 https://code.google.com/p/android-developer-preview/issues/detail?id=731