Vas*_*ant 112 android textview android-imageview material-design
我想在Android Studio中对textview和imageview设置涟漪效果.我该怎么做?
Bik*_*h M 247
参考:http://developer.android.com/training/material/animations.html,
http://wiki.workassis.com/category/android/android-xml/
<TextView
.
.
android:background="?attr/selectableItemBackgroundBorderless"
android:clickable="true"
/>
<ImageView
.
.
.
android:background="?attr/selectableItemBackgroundBorderless"
android:clickable="true"
/>
Run Code Online (Sandbox Code Playgroud)
Mic*_*cro 74
如果您希望将纹波限制为TextView/ImageView的大小,请使用:
<TextView
android:background="?attr/selectableItemBackground"
android:clickable="true"/>
Run Code Online (Sandbox Code Playgroud)
(我觉得它看起来更好)
Vas*_*ant 16
请参考下面的答案以获得涟漪效应。
在Textview或view上产生波纹:
android:clickable="true"
android:focusable="true"
android:foreground="?android:attr/selectableItemBackgroundBorderless"
Run Code Online (Sandbox Code Playgroud)
Button或Imageview上的波纹:
android:foreground="?android:attr/selectableItemBackgroundBorderless"
Run Code Online (Sandbox Code Playgroud)
你可以使用android-ripple-background
开始效果
final RippleBackground rippleBackground=(RippleBackground)findViewById(R.id.content);
ImageView imageView=(ImageView)findViewById(R.id.centerImage);
imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
rippleBackground.startRippleAnimation();
}
});
Run Code Online (Sandbox Code Playgroud)
停止动画:
rippleBackground.stopRippleAnimation();
Run Code Online (Sandbox Code Playgroud)
小智 8
android:background="?android:selectableItemBackground"
android:focusable="true"
android:clickable="true"
Run Code Online (Sandbox Code Playgroud)
添加
android:clickable="true"
android:focusable="true"
对于波纹效果
android:background="?attr/selectableItemBackgroundBorderless"
Run Code Online (Sandbox Code Playgroud)
对于可选择的效果
android:background="?android:attr/selectableItemBackground"
Run Code Online (Sandbox Code Playgroud)
对于按钮效果
android:adjustViewBounds="true" style="?android:attr/borderlessButtonStyle"
Run Code Online (Sandbox Code Playgroud)
小智 5
<TextView
android:id="@+id/txt_banner"
android:layout_width="match_parent"
android:text="@string/banner"
android:gravity="center|left"
android:layout_below="@+id/title"
android:background="@drawable/ripple_effect"
android:paddingLeft="15dp"
android:textSize="15sp"
android:layout_height="45dp" />
Run Code Online (Sandbox Code Playgroud)
将此添加到可绘制
<?xml version="1.0" encoding="utf-8"?>
<!--this ribble animation only working for >= android version 21-->
<ripple
xmlns:android="http://schemas.android.com/apk/res/android"
android:color="@color/click_efect" />
Run Code Online (Sandbox Code Playgroud)
尝试这个。
如果@Bikesh M Annur(此处)发布的投票良好的解决方案对您不起作用,请尝试使用:
<TextView
...
android:background="?android:attr/selectableItemBackgroundBorderless"
android:clickable="true" />
<ImageView
...
android:background="?android:attr/selectableItemBackgroundBorderless"
android:clickable="true" />
Run Code Online (Sandbox Code Playgroud)
另外,在使用android:clickable="true"add 时,android:focusable="true"因为:
"声明为可点击但未声明为可聚焦的小部件无法通过键盘访问。 "
除了上述答案外,还增加了重点,以避免UI编辑器的警告
android:background="?attr/selectableItemBackgroundBorderless"
android:clickable="true"
android:focusable="true"
Run Code Online (Sandbox Code Playgroud)
小智 5
尝试这个。这对我有用。
android:clickable="true"
android:focusable="true"
android:background="?android:attr/selectableItemBackground"
Run Code Online (Sandbox Code Playgroud)
对于圆形波纹:
android:background="?attr/selectableItemBackgroundBorderless"
对于矩形波纹:
android:background="?attr/selectableItemBackground"
| 归档时间: |
|
| 查看次数: |
77485 次 |
| 最近记录: |