关键就这个方法
Animation myAnimation = AnimationUtils.loadAnimation(TestImageAnimactionActivity .this,
R.anim.trans_in);
webView.startAnimation(myAnimation);
Activity:
public class TestImageAnimactionActivity extends Activity {
private Button in;
private Button out;
private WebView imageView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.test_image_animacation);
findView();
initView();
}
private void findView() {
in= (Button) findViewById(R.id.test_image_animacation_in);
out= (Button) findViewById(R.id.test_image_animacation_out);
imageView= (WebView) findViewById(R.id.test_image_animacation_image);
WebSettings webSettings=imageView.getSettings();
SettingsWebViewUtils.setSettings(TestImageAnimaction.this,webSettings);
imageView.setWebChromeClient(new WebChromeClient(){
@Override
public void onProgressChanged(WebView view, int newProgress) {
super.onProgressChanged(view, newProgress);
}
});
imageView.setWebViewClient(new WebViewClient(){
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
return super.shouldOverrideUrlLoading(view, url);
}
});
imageView.loadUrl(API.MAIN_URL);
}
private void initView() {
in.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
myAnimacation(imageView,R.anim.translate_in);
}
});
out.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
myAnimacation(imageView,R.anim.translate_out);
}
});
}
/*
* 动画效果代码
*
* */
public void myAnimacation(WebView webView,int animacation_id){
Animation myAnimation = AnimationUtils.loadAnimation(TestImageAnimaction.this,
animacation_id);
webView.startAnimation(myAnimation);
}
}
Layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/test_image_animacation_in"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="进入"/>
<Button
android:id="@+id/test_image_animacation_out"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="退出"/>
<!--<ImageView
android:id="@+id/test_image_animacation_image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@mipmap/ic_launcher"/>-->
<WebView
android:id="@+id/test_image_animacation_image"
android:layout_width="match_parent"
android:layout_height="match_parent">
</WebView>
</LinearLayout>
in.xml , out.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<translate android:fromXDelta="100%"
android:toXDelta="0%p"
android:duration="1000" />
</set>
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<translate android:fromXDelta="0%"
android:toXDelta="-100%p"
android:duration="1000" />
</set>
哦了 效果如下