【问题标题】:Zooming an imageview to the full screen将图像视图缩放到全屏
【发布时间】:2013-08-14 15:32:28
【问题描述】:

我有一个 xml。其中有一个相对的布局。在那个布局上有一些文本字段。在相对布局的中间有一个 ImageView。我想捏缩放该 imageView 以便它甚至可以缩放到全屏。现在我只能在 ImageView 内放大。就像 ImageView 是一个屏幕,缩放只发生在它里面。但我想相对于整个屏幕进行缩放。当图像被缩放时,我希望 TextFields 保持在那里的位置,但是当图像被缩放时它们应该被覆盖。有什么办法吗?谢谢。

【问题讨论】:

  • 显示xml 代码为imageview

标签: android android-layout android-imageview gesture pinchzoom


【解决方案1】:

在 res 中的 anim 文件夹中创建 zoom_in.xml 并编写以下代码

<?xml version="1.0" encoding="utf-8"?>
<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>

并在您的代码中编写以下代码

public class ZoomInActivity extends Activity implements AnimationListener {

ImageView imgPoster;
Button btnStart;

// Animation
Animation animZoomIn;

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_zoom_in);

    imgPoster = (ImageView) findViewById(R.id.imgLogo);
    btnStart = (Button) findViewById(R.id.btnStart);

    // load the animation
    animZoomIn = AnimationUtils.loadAnimation(getApplicationContext(),
            R.anim.zoom_in);

    // set animation listener
    animZoomIn.setAnimationListener(this);

    // button click event
    btnStart.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // start the animation
            imgPoster.startAnimation(animZoomIn);
        }
    });

}

@Override
public void onAnimationEnd(Animation animation) {
    // Take any action after completing the animation

    // check for zoom in animation
    if (animation == animZoomIn) {          
    }

}

@Override
public void onAnimationRepeat(Animation animation) {
    // TODO Auto-generated method stub

}

@Override
public void onAnimationStart(Animation animation) {
    // TODO Auto-generated method stub

}

}

你的 activity_zoom_in.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:background="#000000"
android:gravity="center">

<ImageView android:id="@+id/imgLogo"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/man_of_steel"
    android:layout_centerInParent="true"/>

<Button android:id="@+id/btnStart"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Start Animation"
    android:layout_marginTop="30dp"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:layout_marginBottom="20dp"/>

</RelativeLayout>

【讨论】:

    猜你喜欢
    • 2018-10-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-10
    • 2011-12-30
    • 1970-01-01
    • 2018-03-02
    • 2011-05-25
    相关资源
    最近更新 更多