VideoView顶部的缩放图像被裁剪

时间:2016-08-22 12:37:29

标签: android imageview android-animation android-videoview

我正在尝试使用Android App Development并面临与VideoView相关的一些问题。 我正在使用动画师来缩放我的图像。代码如下:

  

MainActivity.java

private MediaPlayer mediaPlayer;
private SurfaceHolder vidHolder;
private SurfaceView vidSurface;
private VideoView videoView;
String vidAddress = "https://archive.org/download/ksnn_compilation_master_the_internet/ksnn_compilation_master_the_internet_512kb.mp4";

public void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    videoView = (VideoView) findViewById(R.id.VideoView);
    try {
        Uri videoURL = Uri.parse(vidAddress);
        videoView.setVideoURI(videoURL);

    } catch (Exception e) {
        Log.e("Error", e.getMessage());
        e.printStackTrace();
    }

    videoView.requestFocus();
    videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
        public void onPrepared(MediaPlayer mp) {
            videoView.start();
        }
    });
    ImageView imageView = (ImageView) findViewById(R.id.imageView);
    AnimatorSet set = (AnimatorSet) AnimatorInflater.loadAnimator(this, R.animator.image_anim);
    set.setTarget(imageView);
    set.start();
}
  

activity_main.xml中

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#000000"
    tools:context=".MainActivity" >

    <VideoView
        android:id="@+id/VideoView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"/>


    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/imageView"
        android:layout_centerVertical="true"
        android:layout_centerHorizontal="true"
        android:src="@raw/logo"
        android:visibility="visible"/>

</RelativeLayout>
  

image_anim.xml

<set xmlns:android="http://schemas.android.com/apk/res/android" android:ordering="together">
    <objectAnimator
        android:propertyName="scaleX"
        android:duration="10000"
        android:valueFrom="1"
        android:startOffset="5000"
        android:valueTo="2"
        android:valueType="floatType"/>
    <objectAnimator
        android:propertyName="scaleY"
        android:duration="10000"
        android:valueFrom="1"
        android:startOffset="5000"
        android:valueTo="2"
        android:valueType="floatType"/>
</set>

活动开始时图像显示正常。但是当它缩放时,我无法看到超出其原始尺寸的图像。换句话说,它会被裁剪到原始尺寸的区域之外。

我认为它与VideoView的以下问题有些相关,但不知道如何解决它。

https://stackoverflow.com/a/22101290/3530685

为了更好地理解,这就是正在发生的事情 Before Scaling

After Scaling

如果删除VideoView,缩放就会很好。如何在没有因VideoView而裁剪图像的情况下正确缩放图像?

编辑:我在另一台安装了Android 5.1.1的设备上进行了测试,效果很好。但是在使用Android 4.0.4的模拟器或设备中无法正常工作

0 个答案:

没有答案
相关问题