【问题标题】:How can i decrease image size when image is falling from top to bottom?当图像从上到下下降时,如何减小图像尺寸?
【发布时间】:2018-05-14 21:02:37
【问题描述】:

当图像从上到下下降时如何减小图像尺寸?

我已经通过下面的链接开发了从上到下的流程

Android Layout Animations from bottom to top and top to bottom on ImageView click

但我面临一个问题。当图像从上到下下降时如何减小图像尺寸?

请让我分享您的想法或链接和代码。

请在下图中查看我的要求。

【问题讨论】:

    标签: android android-layout android-studio zooming


    【解决方案1】:

    您可以对该视图应用比例变换。

    Matrix matrix = new Matrix();
    matrix.setScale(valueX, valueY);
    view.setTransform(matrix); 
    

    对于图像视图

    imageView.setImageMatrix(matrix);
    

    【讨论】:

      【解决方案2】:

      我解决了我的问题。希望大家喜欢。

      1.创建anim/zoom_out.xml

      <?xml version="1.0" encoding="utf-8"?>
      <set xmlns:android="http://schemas.android.com/apk/res/android"
      android:interpolator="@android:anim/decelerate_interpolator"
      android:fillAfter="true">
      <scale
          android:duration="5000"
          android:fromXScale="100%"
          android:fromYScale="100%"
          android:pivotX="50%"
          android:pivotY="50%"
          android:toXScale="50%"
          android:toYScale="50%" />
      
      <translate
          android:duration="5000"
          android:fromYDelta="10%"
          android:toYDelta="50%" />
      

      2.activity_main.xml

      <?xml version="1.0" encoding="utf-8"?>
      <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:paddingLeft="10dp"
      android:paddingRight="10dp">
      <ImageView android:id="@+id/imgvw"
          android:layout_width="wrap_content"
          android:layout_height="250dp"
          android:src="@mipmap/ic_launcher"/>
      <Button
          android:id="@+id/btnZoomIn"
          android:layout_below="@+id/imgvw"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="Zoom In" android:layout_marginLeft="100dp" />
      <Button
          android:id="@+id/btnZoomOut"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_alignBottom="@+id/btnZoomIn"
          android:layout_toRightOf="@+id/btnZoomIn"
          android:text="Zoom Out" />
      </RelativeLayout>
      

      3.MainActivity.java 文件

      public class MainActivity extends AppCompatActivity {
      private Button btnzIn;
      private Button btnzOut;
      private ImageView img;
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          btnzIn = (Button)findViewById(R.id.btnZoomIn);
          btnzOut = (Button)findViewById(R.id.btnZoomOut);
          img = (ImageView)findViewById(R.id.imgvw);
        /*  btnzIn.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
      
                //  img.startAnimation(AnimationUtils.loadAnimation(getApplicationContext(),R.anim.zoom_in));
                  img.startAnimation(AnimationUtils.loadAnimation(getApplicationContext(), R.anim.slide_down));
                 // img.clearAnimation();
              }
          });*/
          btnzOut.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
      
              //    img.startAnimation(AnimationUtils.loadAnimation(getApplicationContext(), R.anim.slide_up));
                  img.startAnimation(AnimationUtils.loadAnimation(getApplicationContext(),R.anim.zoom_out));
      
              }
          });
      }
      

      【讨论】:

        猜你喜欢
        • 2011-12-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-01-24
        • 1970-01-01
        • 2015-01-27
        相关资源
        最近更新 更多