单击图像视图中心的阴影

时间:2014-05-16 13:15:31

标签: android xml layout

我试图在按下状态时在中心显示圆角阴影。 但它在当前情况下给出了全视图(矩形)阴影。 这就是我想要的...... 1. left_button.xml

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

<item android:state_pressed="true">

<shape >
        <solid android:color="#ffffff"></solid>
                </shape>

    </item>

<item android:state_focused="true"><shape>
        <solid android:color="#40454a"></solid>
    </shape></item>
<item><shape>
        <solid android:color="#40454a"></solid>
    </shape></item>

</selector>

这是我正在应用的xml布局......

 <RelativeLayout
        android:id="@+id/relative_activity_camera_bottom"
        android:layout_width="fill_parent"
        android:layout_height="50dp"
        android:layout_alignParentBottom="true"
        android:gravity="center_vertical"
        android:background="@layout/footer_color" >
    <LinearLayout
        android:id="@+id/bottom_layout1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="horizontal"
        android:background="@android:color/transparent"
        android:gravity="center_vertical"
        android:weightSum="1.0" >
        <ImageView
            android:id="@+id/captureImage"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent" 
            android:layout_weight="0.5"
            android:background="@layout/left_button" 
            android:src="@layout/camera_image"
             />


        <ImageView
            android:id="@+id/recordButton"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"  
            android:layout_weight="0.5"
            android:src="@layout/videocamera_image"
            android:background="@layout/left_button" 
            android:onClick="startRecording"
             />

            </LinearLayout>
    </RelativeLayout>

原始条件 - enter image description here

当前案例 - enter image description here(但我想仅在中心显示白色)

1 个答案:

答案 0 :(得分:1)

例如,使用选择器:

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

    <item android:drawable="@drawable/gradient_round_press_effect" android:state_selected="true" android:state_window_focused="false"/>
    <item android:drawable="@drawable/gradient_round_press_effect" android:state_selected="true"/>
    <item android:drawable="@drawable/gradient_round_press_effect" android:state_pressed="true" android:state_selected="false"/>
    <item android:drawable="@drawable/gradient_round_press_effect_inverse" android:state_selected="false"/>

</selector>

有两个可绘制的形状,第一个点击时(gradient_round_press_effect):

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

    <gradient
        android:endColor="@color/clr_the_color_behind"
        android:gradientRadius="130"
        android:startColor="#66000000"
        android:type="radial" />

</shape>

根据按钮的大小调整半径大小

对于开始颜色,如果你想要白色(66是透明度),请使用#66FFFFFF

对于最终颜色,您可以使用透明色吗?我没试过这个

并且在未单击时定义您自己的颜色(gradient_round_press_effect_inverse)并非真正“反向”,但这是另一个渐变的示例。您只需使用颜色

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

    <gradient
        android:angle="270"
        android:centerColor="@color/clr_gradient2"
        android:endColor="@color/clr_gradient1"
        android:startColor="@color/clr_gradient3"
        android:type="linear" />

</shape>