截图效果Android

San*_*nor 5 java android

我想创建一个屏幕效果,就像你在手机中截取屏幕截图一样,我的意思是,当我点击一个按钮时屏幕上有点闪光,我也想改变那个闪光灯的颜色.那可能吗?非常感谢你提前;)

Sco*_*ott 12

获得此效果的简单方法是具有以下内容:

在布局上创建一个空的"面板".例如:

<?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">
    <LinearLayout
        android:layout_height="wrap_content"
        android:layout_width="fill_parent">
        <!-- Your normal layout in here, doesn't have to be a LinearLayout -->
    </LinearLayout>
    <FrameLayout
        android:id="@+id/pnlFlash"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="[Set to your desired flash colour, image, etc]"
        android:visibility="gone"
        />
</FrameLayout>
Run Code Online (Sandbox Code Playgroud)

ID为'pnlFlash'的FrameLayout仍然隐藏起来,因此不会干扰正常的交互.

现在,当你想制作闪光灯时,你所要做的就是让面板尽可能长时间显示.有一个很好的淡出也总是有帮助.

pnlFlash.setVisibility(View.VISIBLE);

AlphaAnimation fade = new AlphaAnimation(1, 0);
fade.setDuration(50);
fade.setAnimationListener(new AnimationListener() {
    ...
    @Override
    public void onAnimationEnd(Animation anim) {
        pnlFlash.setVisibility(View.GONE);
    }
    ...
});
pnlFlash.startAnimation(fade);
Run Code Online (Sandbox Code Playgroud)

我之前没有使用过这种代码,因此您可能需要相应地调整持续时间.