2017-07-11 17 views
1

最近、私は問題で唖然としました。私のアンドロイドでは、同じ仰角のリストまたはスクロールビューの電話要素は、その配置に関連して異なる影を持っています。例えば、画面の上部にのビューは、画面の下部にのビューが表示されるたびに小さな光の影を持っていますは、より暗くて強い影を持っています。ここではGoogleからのスクリーンショットは、アプリケーションをキープです:同じビューの高さは、上面図と下面図で異なって見えます

If you will look at first card view and last one, you will see different shadows

だから、私はこれが原因で正確にGoogleキープアプリケーションであることを考えました。たぶん、Googleからの人たちは、そのアプリケーションのための陰影でそのトリックをすることにしました。したがって、サンプルアプリケーションを作成しました。

マイレイアウト:

<?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"> 

    <TextView 
     style="@style/AppButton" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_margin="16dp" 
     android:text="Test"/> 

    <TextView 
     style="@style/AppButton" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_margin="16dp" 
     android:text="Test"/> 

    <TextView 
     style="@style/AppButton" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_margin="16dp" 
     android:text="Test"/> 

    <TextView 
     style="@style/AppButton" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_margin="16dp" 
     android:text="Test"/> 

    <TextView 
     style="@style/AppButton" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_margin="16dp" 
     android:text="Test"/> 

    <TextView 
     style="@style/AppButton" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_margin="16dp" 
     android:text="Test"/> 

    <TextView 
     style="@style/AppButton" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_margin="16dp" 
     android:text="Test"/> 

</LinearLayout> 

私のスタイル:

<?xml version="1.0" encoding="utf-8"?> 
<resources> 

    <!-- Base application theme. --> 
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> 
     <!-- Customize your theme here. --> 
     <item name="colorPrimary">@color/colorPrimary</item> 
     <item name="colorPrimaryDark">@color/colorPrimaryDark</item> 
     <item name="colorAccent">@color/colorAccent</item> 
    </style> 

    <style name="AppButton"> 
     <item name="android:background">@color/colorAccent</item> 
     <item name="android:elevation">4dp</item> 
     <item name="android:gravity">center</item> 
     <item name="android:padding">16dp</item> 
     <item name="android:textColor">@android:color/white</item> 
    </style> 

</resources> 

、出力は次のとおりです。

enter image description here

ご覧のとおり、同じ効果があります(上の図は小さな影、下の図は大きな影)。だから私の質問は:

  1. 私は間違っていましたか?
  2. どのようにすべてのビュー(位置によって異なる)で同じ影を達成できますか?
  3. また、私はドキュメントで何の説明も見つけられていないので、どこでその現象について読むことができますか?
  4. すべてのデバイスで、または特定のデバイスでのみ発生しますか?

P.S:私はネクサス5X、アンドロイド7.1.2を持っています。

UPD: 重要な言葉は、Android Studioのプレビューウィンドウからすべて正常です。すべてのビューは他のビューと同じ影を持ちます。しかし、実際のデバイスでは、違いを見ることができます。

+0

は、影が一番下にあります。 https://material.io/guidelines/components/cards.html# https://material.io/guidelines/material-design/elevation-shadows.html#elevation-shadows-shadows – tyczj

+0

@tyczj実際には、私は持っているあなたの説明と私たちが異なることについて話すことに気づいた。すべてのシャドウは上から下にキャストされますが、リストのトップビューとリストの最下部のビューを見ると、そのシャドウは異なりますが、どちらのビューも 'elevation = 4dp'になります。しかし、ユーザーにとっては、画面上部のビューは2-3dpの標高を持ち、画面下部のビューは4-5dpの標高を持っているように見えます。 –

答えて

1

Elevation APIによって生成された影は3D空間に配置されます。つまり、各影の外観は標高値だけでなく、シャドウキャスターのxとyの画面上の位置によっても影響を受けます。現実世界のようなものです。光源の下のオブジェクトは、離れたオブジェクトよりも短い影を投げかけます。

投稿した最初の画像を詳しく見てください。影は、左のカードの左端で、右のカードの右端では、水平の中央の端より長くなります。

広告。 1.何もない。それだけでそのように動作します。

広告。 2. Elevation APIを使用することはできません。自分で影を描くことができます。

広告。 3.わかりません、申し訳ありません。

広告。 4.すべてのデバイス。

広告。 UPD。エディタの影は静的なので、観察しても効果はありません。光源は、トップからすると仮定されているため、カードが見えるように仮定されている方法をあなたは何も間違ってthatsの操作を行うdidntは

enter image description here

+0

ありがとうございます。それはあなたが正しいと思われ、何も標準的なAPIを介して行うことはできません。ありがとうございました! –