2

私はxmlを持っています。これは相対的なレイアウトを持っています。そして、そのレイアウトにはいくつかの TextFields があります。相対レイアウトの真ん中に ImageView があります。そのimageViewをピンチズームして、全画面にズームできるようにしたい。これで、ImageView 内でのみズームできます。ImageView が画面であり、ズームがその内部でのみ発生するように。しかし、画面全体に対してズームしたい。画像がズームされたときに TextFields がその位置を維持するようにしたいのですが、画像がズームされたときにそれらをカバーする必要があります。それを行う方法はありますか?ありがとう。

4

1 に答える 1

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>
于 2013-08-13T06:26:58.620 に答える