2015-11-15 2 views
0

Я пытаюсь добавить тень к своему пользовательскому представлению на устройстве pre-lollipop. Я использую этот XML:Добавить тень к пользовательскому представлению pre-lollipop

<?xml version="1.0" encoding="utf-8"?> 
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> 

    <item android:top="8px"> 
     <layer-list> 
      <item> 
       <shape android:shape="oval"> 
        <solid android:color="#08000000"/> 
        <padding 
         android:bottom="3px" 
         android:left="3px" 
         android:right="3px" 
         android:top="3px" 
         /> 
       </shape> 
      </item> 
      <item> 
       <shape android:shape="oval"> 
        <solid android:color="#09000000"/> 
        <padding 
         android:bottom="2px" 
         android:left="2px" 
         android:right="2px" 
         android:top="2px" 
         /> 
       </shape> 
      </item> 
      <item> 
       <shape android:shape="oval"> 
        <solid android:color="#10000000"/> 
        <padding 
         android:bottom="2px" 
         android:left="2px" 
         android:right="2px" 
         android:top="2px" 
         /> 
       </shape> 
      </item> 
      <item> 
       <shape android:shape="oval"> 
        <solid android:color="#11000000"/> 
        <padding 
         android:bottom="1px" 
         android:left="1px" 
         android:right="1px" 
         android:top="1px" 
         /> 
       </shape> 
      </item> 
      <item> 
       <shape android:shape="oval"> 
        <solid android:color="#12000000"/> 
        <padding 
         android:bottom="1px" 
         android:left="1px" 
         android:right="1px" 
         android:top="1px" 
         /> 
       </shape> 
      </item> 
      <item> 
       <shape android:shape="oval"> 
        <solid android:color="#13000000"/> 
        <padding 
         android:bottom="1px" 
         android:left="1px" 
         android:right="1px" 
         android:top="1px" 
         /> 
       </shape> 
      </item> 
      <item> 
       <shape android:shape="oval"> 
        <solid android:color="#14000000"/> 
        <padding 
         android:bottom="1px" 
         android:left="1px" 
         android:right="1px" 
         android:top="1px" 
         /> 
       </shape> 
      </item> 
      <item> 
       <shape android:shape="oval"> 
        <solid android:color="#15000000"/> 
        <padding 
         android:bottom="1px" 
         android:left="1px" 
         android:right="1px" 
         android:top="1px" 
         /> 
       </shape> 
      </item> 

     </layer-list> 
    </item> 

    <item android:drawable="@drawable/ripple" android:state_pressed="false"/> 
    <item android:drawable="@drawable/ripple_dark" android:state_pressed="true"/> 

</layer-list> 

И в моем макете:

<ImageButton 
    android:id="@+id/view" 
    android:layout_width="54dp" 
    android:layout_height="54dp" 
    android:layout_alignParentBottom="true" 
    android:layout_alignParentRight="true" 
    android:layout_alignParentEnd="true" 
    android:layout_gravity="bottom|right|end" 
    android:layout_marginBottom="16dp" 
    android:layout_marginEnd="16dp" 
    android:layout_marginRight="16dp" 
    android:background="@drawable/background" 
    android:contentDescription="@string/play" 
    android:src="@drawable/image" /> 

Проблема заключается в том, что я хочу, изображение кнопки, чтобы быть 54dpx54dp, но если добавить отступы внутреннее изображение меньше. Я должен добавить больше dp для компенсации заполнения, но я не знаю, как я могу это сделать. Любая помощь?

ответ

0

Просто добавьте ниже точки зрения в нижней части каждого элемента, который нуждается в тени:

<View 
    android:id="@+id/shadow" 
    android:layout_width="fill_parent" 
    android:layout_height="5dp" 
    android:layout_below="@+id/..." 
    android:background="@drawable/drop_shadow" /> 

drop_shadow.xml:

<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android"> 
    <gradient 
    android:startColor="#bfbbbf" 
    android:endColor="#F1F1F1" 
    android:angle="270"> 
    </gradient> 
</shape> 
Смежные вопросы