JS交互和属性动画

XML
<LinearLayout
android:layout_width=“match_parent”
android:layout_height=“match_parent”
android:orientation=“vertical”
<Button
android:id="@+id/button"
android:layout_width=“match_parent”
android:layout_height=“wrap_content”
android:text=“点击调用”
<WebView
android:id="@+id/web"
android:layout_width=“match_parent”
android:layout_height=“wrap_content”

public class JsActivity extends AppCompatActivity {

private WebView webview;
private Button button;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_js);

    webview = findViewById(R.id.web);
    button = findViewById(R.id.button);
    findViewById(R.id.dian).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(JsActivity.this,DongHuaActivity.class);
            JsActivity.this.startActivity(intent);
        }
    });
    button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            webview.loadUrl("javascript:callJS()");
        }
    });
    WebSettings settings = webview.getSettings();
    settings.setJavaScriptEnabled(true);
    settings.setJavaScriptCanOpenWindowsAutomatically(true);
    webview.loadUrl("file:///android_asset/test.html");
    //支持js弹框
    webview.setWebChromeClient(new WebChromeClient(){
        @Override
        public boolean onJsAlert(WebView view, String url, String message, JsResult result) {
            return super.onJsAlert(view, url, message, result);
        }
    });
}

}
//动画
s DongHuaActivity extends AppCompatActivity {

private ImageView image;
private Button but;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_dong_hua);
    image = findViewById(R.id.image_donghua);
    but = findViewById(R.id.but_donghua);
    but.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            // 垂直移动
            float curTranslationY = image.getTranslationY();
            ObjectAnimator translationY = ObjectAnimator.ofFloat(image, "translationY",
                    curTranslationY, curTranslationY + 100f);

            ObjectAnimator scaleY = ObjectAnimator.ofFloat(image, "scaleY", 1f, 5f, 1f);
            ObjectAnimator scaleX = ObjectAnimator.ofFloat(image, "scaleX", 1f, 5f, 1f);

            AnimatorSet animSet = new AnimatorSet();
            animSet.play(scaleY).with(scaleX).after(translationY);
            animSet.setDuration(2000);
            animSet.start();

// //360旋转
// ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(image,“rotation”,0,360);
// ObjectAnimator objectAnimator1 = ObjectAnimator.ofFloat(image,“translationY”,0,100);
// AnimatorSet animatorSet = new AnimatorSet();
// animatorSet.play(objectAnimator).after(objectAnimator1);
// animatorSet.setDuration(3000);
// animatorSet.start();
}
});
}
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值