【问题标题】:add effect on image view在图像视图上添加效果
【发布时间】:2014-03-08 21:19:09
【问题描述】:

我想在点击时在图像上添加效果,我想要透明效果而不是任何颜色。

这是我的代码。

`<LinearLayout
            android:layout_width="282dp"
            android:layout_height="match_parent"
            android:layout_gravity="center"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            android:gravity="center" >

            <ImageView
                android:id="@+id/ivcontactfb"
                android:layout_width="45dp"
                android:layout_height="45dp"
                android:src="@drawable/fb"
                 style="@style/DefaultButton"/>

            <ImageView
                android:id="@+id/ivcontacttw"
                android:layout_width="45dp"
                android:layout_height="45dp"
                android:src="@drawable/tw"
                android:layout_marginLeft="20dp" 
                style="@style/DefaultButton"/>

            <ImageView
                android:id="@+id/ivcontactin"
                android:layout_width="45dp"
                android:layout_height="45dp"
                android:src="@drawable/in"
                android:layout_marginLeft="20dp"
                style="@style/DefaultButton"/>
        </LinearLayout>`

请帮帮我, 谢谢。

【问题讨论】:

    标签: android effect


    【解决方案1】:

    如果您想在单击时更改效果,您可能应该使用ImageButton 而不是ImageView 并进行如下设置:

    <ImageButton
        android:id="@+id/ivcontactfb"
        android:layout_width="45dp"
        android:layout_height="45dp"
        android:src="@drawable/imageview_states"
        style="@style/DefaultButton"/>
    

    并在您的可绘制资源中创建一个自定义 xml 文件:

    drawable/imageview_states.xml

    <selector xmlns:android="http://schemas.android.com/apk/res/android">
        <item android:state_focused="true" android:state_pressed="true" android:drawable="@drawable/media_icon_pressed"/>
        <item android:state_focused="false" android:state_pressed="true" android:drawable="@drawable/media_icon_pressed"/>
        <item android:state_focused="true" android:drawable="@drawable/media_icon_selected"/>
        <item android:state_focused="false" android:state_pressed="false" android:drawable="@drawable/media_icon_default"/>
    </selector>
    

    【讨论】:

    • 我的图像没有设置在图像按钮中,这就是我使用图像视图的原因...
    • 有什么方法可以使用效果来查看图片吗?
    • 呃,为什么不设置在imagebutton中?
    • 您可以尝试对 ImageView 执行相同操作。设置背景并使用相同的可绘制资源。不知道它是否适用于 ImageView
    • 我的图像是圆形的,如果我对其应用效果,它就会变成方形...
    猜你喜欢
    • 2015-07-13
    • 2016-11-03
    • 2019-01-21
    • 2020-02-03
    • 2023-03-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-01
    相关资源
    最近更新 更多