放大缩小动画
我正在测试单击图像时放大/缩小动画。但是我没有得到我想要的结果。图像完全放大,但不完全缩小。为了更好地理解我的问题,请参阅this video。放大缩小动画
这里是我的代码:
zoom_in.XML
<set xmlns:android="http://schemas.android.com/apk/res/android" android:fillAfter="true" >
<scale
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="1000"
android:fromXScale="1"
android:fromYScale="1"
android:pivotX="50%"
android:pivotY="50%"
android:toXScale="3"
android:toYScale="3" >
</scale>
</set>
zoom_out.xml
<set xmlns:android="http://schemas.android.com/apk/res/android" android:fillAfter="true" >
<scale
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="1000"
android:fromXScale="1.0"
android:fromYScale="1.0"
android:pivotX="50%"
android:pivotY="50%"
android:toXScale="0.5"
android:toYScale="0.5" >
</scale>
mainacti VITY
public class MainActivity extends Activity
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ImageButton pic = (ImageButton) findViewById(R.id.levelimg);
pic.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v){
final Dialog dialog = new Dialog(MainActivity.this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.dialogpic);
dialog.getWindow().getAttributes().windowAnimations = R.style.DialogAnimation;
dialog.show();
}
});
}
}
我dailog动画风格
<style name="DialogAnimation">
<item name="android:windowEnterAnimation">@anim/zoom_in</item>
<item name="android:windowExitAnimation">@anim/zoom_out</item>
</style>
更改您的缩放列如下代码,并检查一次,让我,如果它不能正常工作。
<set xmlns:android="http://schemas.android.com/apk/res/android" android:fillAfter="true" >
<scale
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="
1000"
android:fromXScale="1.0"
android:fromYScale="1.0"
android:pivotX="50%"
android:pivotY="50%"
android:toXScale="0"
android:toYScale="0" >
</scale>
用这个改变你的代码。
zoom_in.xml
<scale
android:duration="@android:integer/config_shortAnimTime"
android:fromXScale="0.3"
android:fromYScale="0.3"
android:pivotX="50%"
android:pivotY="50%"
android:toXScale="1.0"
android:toYScale="1.0" />
zoom_out.xml
<scale
android:duration="@android:integer/config_shortAnimTime"
android:fromXScale="1.0"
android:fromYScale="1.0"
android:pivotX="50%"
android:pivotY="50%"
android:toXScale="0"
android:toYScale="0" />
这将为你做的伎俩。 :)
试图如你所说,但它没有从他们的图像中心放大,当后退按钮被按下时,再次放大,然后关闭 – user5524159
如果你想让你的imageview放大zoom out anim,使用这个库https://github.com/daimajia/AndroidViewAnimations。 – Aks4125
亚哥我会看看它 – user5524159
试试这个
public class MainActivity extends Activity {
private ImageView iv;
private Matrix matrix = new Matrix();
private float scale = 1f;
private ScaleGestureDetector SGD;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
iv=(ImageView)findViewById(R.id.imageView);
SGD = new ScaleGestureDetector(this,new ScaleListener());
}
public boolean onTouchEvent(MotionEvent ev) {
SGD.onTouchEvent(ev);
return true;
}
private class ScaleListener extends ScaleGestureDetector.
SimpleOnScaleGestureListener {
@Override
public boolean onScale(ScaleGestureDetector detector) {
scale *= detector.getScaleFactor();
scale = Math.max(0.1f, Math.min(scale, 5.0f));
matrix.setScale(scale, scale);
iv.setImageMatrix(matrix);
return true;
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
http://developer.android.com/training/animation/zoom.html这就是你要做的? –
如果您尝试采用具有缩放功能的图片的点击事件,则无法正确点击该事件,因为动画仅会更改视图的用户界面,但不会更改当前位置,因此当您点击放大的图片时不会点击它 –