棒棒糖上类似视图的不同阴影大小

时间:2016-02-25 07:05:07

标签: android performance android-layout

我的布局包含素材样式按钮,单击时会显示。在棒棒糖按钮上,屏幕底部的阴影大于屏幕顶部的按钮阴影。屏幕底部的按钮阴影看起来很难看。我可以为按钮禁用此渲染效果吗?

布局:

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

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">

    <Button
        style="@style/Base.Widget.AppCompat.Button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="top|center_horizontal"
        android:layout_marginTop="80dp"
        android:background="@drawable/button_blue"
        android:text="BUTTON" />

    <View
        android:layout_width="100dp"
        android:layout_height="60dp"
        android:layout_gravity="center|top"
        android:layout_marginTop="160dp"
        android:background="@drawable/button_blue"
        android:clickable="true"
        android:stateListAnimator="@xml/state_list_animator" />

    <Button
        style="@style/Base.Widget.AppCompat.Button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center|bottom"
        android:layout_marginBottom="20dp"
        android:background="@drawable/button_blue"
        android:text="BUTTON" />

    <View
        android:layout_width="100dp"
        android:layout_height="60dp"
        android:layout_gravity="center|bottom"
        android:layout_marginBottom="100dp"
        android:background="@drawable/button_blue"
        android:clickable="true"
        android:stateListAnimator="@xml/state_list_animator" />

</FrameLayout>  

button_blue(drawable-v21):

<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="@color/button_blue_pressed">
<item>
    <shape>
        <solid android:color="@color/button_blue" />
        <corners android:radius="2dp" />
        <padding
            android:left="8dp"
            android:right="8dp" />
    </shape>
</item>
</ripple>

state_list_animator:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
    android:state_enabled="true"
    android:state_pressed="true">
    <set>
        <objectAnimator
            android:duration="100"
            android:propertyName="translationZ"
            android:valueTo="6"
            android:valueType="floatType" />
        <objectAnimator
            android:duration="0"
            android:propertyName="elevation"
            android:valueTo="2"
            android:valueType="floatType" />
    </set>
</item>
<!-- base state -->
<item android:state_enabled="true">
    <set>
        <objectAnimator
            android:duration="100"
            android:propertyName="translationZ"
            android:startDelay="20"
            android:valueTo="1"
            android:valueType="floatType" />
        <objectAnimator
            android:duration="0"
            android:propertyName="elevation"
            android:valueTo="2"
            android:valueType="floatType" />
    </set>
</item>
</selector>  

结果: result

谷歌新闻应用程序具有此效果: google news app with this effect

0 个答案:

没有答案