android5 Ripple和Reveal动效
Ripple水波纹效果(Button自带)
效果图:
代码:
xml文件
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="www.weshared.android5.MainActivity">
<!--android5.0以上版本自带效果 -->
<Button
android:id="@+id/btn1"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_gravity="center_horizontal"
android:layout_margin="30dp"
android:layout_weight="1"
android:elevation="10dp"
android:text="A" />
<!--android:background="?android:attr/selectableItemBackground" 设置有波纹边界-->
<!--或者 android:background="?attr/selectableItemBackground" 设置有波纹边界-->
<Button
android:id="@+id/btn2"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_gravity="center_horizontal"
android:layout_margin="30dp"
android:layout_weight="1"
android:background="?android:attr/selectableItemBackground"
android:elevation="10dp"
android:text="b" />
<!--android:background="?android:attr/selectableItemBackgroundBorderless" 设置无波纹边界 -->
<!--或者 android:background="?attr/selectableItemBackgroundBorderless" 设置无波纹边界 -->
<Button
android:id="@+id/btn3"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_gravity="center_horizontal"
android:layout_margin="30dp"
android:layout_weight="1"
android:background="?attr/selectableItemBackgroundBorderless"
android:elevation="10dp"
android:text="c" />
</LinearLayout>
在style.xml文件中,可以设置水波纹的颜色
<!--控制水波纹的颜色-->
<item name="android:colorControlHighlight">@color/colorPrimary</item>
Reveal动效:
效果图:
xml布局文件省略,直接看代码
public class ThirdActivity extends AppCompatActivity {
private TextView textView;
private ImageView imageView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_third);
textView = (TextView) findViewById(R.id.tv_third);
imageView = (ImageView) findViewById(R.id.iv_third);
textView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ViewAnimationUtils.createCircularReveal(textView, textView.getWidth() / 2, textView.getHeight() / 2, 30, 400).setDuration(2000).start();
}
});
imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ViewAnimationUtils.createCircularReveal(imageView, 0, imageView.getHeight(), imageView.getWidth() / 4, imageView.getWidth() * 2).setDuration(2000).start();
}
});
}
}