android:elevation数日間 L プレビューで遊んでいますが、ビューの属性がうまくいかないようです。を呼び出す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
I セットによればandroid:elevation、一番下のカードは「地面」に平らに置かれるべきですが、そうではありません。実際、標高が である一番上のカードと同じように見えます5dp。これは既知の問題ですか?
編集:これは のみの場合でCardViewあるか、少なくとも では問題ではないようButtonsです。このレイアウトでは、 に置き換えましCardViewたButton。影が多少おかしくなっていますが (既知のバグ)、高さの違いを確認できます。
<?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を aに置き換えて、drawableFrameLayoutに設定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