2017-06-19 10 views
0

私はsetElevationで影を描くことができません。これを行うために図面を使用したくありません。コードは次のとおりです。
これは親です。
Page.xmlここ
setElevationに影が表示されない

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    android:background="@color/background"> 

    <LinearLayout 
     android:id="@+id/pp_cont_new_list" 
     android:background="@color/background" 
     android:layout_width="match_parent" 
     android:layout_height="150dp" 
     android:gravity="center_horizontal" 
     android:orientation="vertical" 
     android:paddingLeft="30dp" 
     android:paddingRight="30dp" 
     android:paddingTop="5dp"> 
    </LinearLayout> 

</LinearLayout> 

私はシンプルなレイアウトを構築します。
PersonalPage.Java

final LinearLayout ROOT = (LinearLayout) findViewById(R.Id.pp_cont_new_list); 
final LinearLayout LL = new LinearLayout(context); //Container 
LL.setLayoutParams (new LinearLayout.LayoutParams(
    Generic.PARAM_MP, //eq. match_parent 
    (int) context.getResources().getDimension (R.dimen.bt_preview_list_height) 
)); 
LL.setBackgroundResource (R.drawable.background_new_list); 
LL.setElevation (5f); 
LL.setClickable (true); 

ROOT.addView(LL); 
/* 
* other code inner the container 
*/ 

この背景
background_new_list.xml

<?xml version="1.0" encoding="utf-8"?> 
<layer-list 
    xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item> 
     <shape android:shape="rectangle"> 
      <corners android:radius="10dp"/> 
      <solid android:color="@color/background"/> 
     </shape> 
    </item> 
    <item> 
     <ripple android:color="@color/textColorAlpha"/> 
    </item> 
</layer-list> 

私は私のエラーの説明をしたいと思います。
また、私は前にLOLLIPOPを使用するかどうかを知りたいと思います。

+0

ロリポップ以上の溶液。子ビューに影を表示させる正しい方法は、親にパディングを設定し、その親に 'android:clipToPadding =" false "'を設定することです。ここにその説明があります。 https://stackoverflow.com/a/27518160/886148 –

+0

for wick.ed:そこにパディングがありますが、ソリューションを追加しても機能しない場合でも、 – Thorny84

+0

パディングを親レイアウトに追加しましたか?更新されたコードを教えてください。また、 'color/background'の値は –

答えて

1

セット標高だけdoesnotあなたが影を持つカスタムボタン画像を作成し、シャドウ効果に

+0

ですが、私のコードはLOLLIPOPの前とLOLLIPOPの後では動作しません。 – Thorny84

0

使用を与えるためにボタンbackground..or任意のビューの背景として設定することができ、プリロリポップ

のために働くViewCompat.setElevation(your_view(in your case LL), elevation_amount); が、デバイス事前ロリポップのために、これは、あなたが使用する可能性のある前ロリポップの例について を効果がありません。

android:background="@android:drawable/dialog_holo_light_frame" 
+0

これを試しましたが、うまくいきません – Thorny84

0

あなたはXMで物事を気にしない場合、これが機能していますl。私はそれを試しました。あなたが使用している背景色の値がないので、親のレイアウトに別の色を使用しました。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:background="#E8E8E8" 
android:paddingBottom="20dp" 
android:clipToPadding="false" 
android:translationZ="6dp"> 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="150dp" 
    android:background="@drawable/background_new_list" 
    android:clipToPadding="false" 
    android:elevation="25dp" 
    android:orientation="vertical" 
    /> 

注:私はちょうどそれが働いている場合、それは簡単にチェックできるようにすること、より高い標高値を使用しています。必要なものに調整することができます。

関連する問題