滚动时如何避免surfaceview收缩?

时间:2013-07-03 09:30:47

标签: android-layout surfaceview

在我的项目中,我需要有水平列表视图,项目是surfaceview的显示视频,因为我滚动列表视图下一个视频必须显示,它在所有的手机和平板电脑上工作正常,但在LG NEXUS 4时我执行滚动,surfaceview正在缩小,请提供任何建议。

感谢。

请在此处找到相关代码。

enter code herepackage com.example.videopager;

import android.app.Activity;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.view.Menu;

public class MainActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        MyPagerAdapter adapter = new MyPagerAdapter();
        ViewPager myPager = (ViewPager) findViewById(R.id.myfivepanelpager);
        myPager.setAdapter(adapter);
        myPager.setCurrentItem(1);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

}
package com.example.videopager;

import android.content.Context;
import android.net.Uri;
import android.os.Parcelable;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.VideoView;

public class MyPagerAdapter extends PagerAdapter {

    public VideoView mVideoView;

    public int getCount() {
        return 3;
    }

    public Object instantiateItem(View collection, int position) {
        LayoutInflater inflater = (LayoutInflater) collection.getContext()
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        int resId = 0;
        View view = null;
        switch (position) {
        case 0:
            resId = R.layout.video1;
            view = inflater.inflate(resId, null);

            break;
        case 1: // TODO : change media file path accordingly
            resId = R.layout.video2;
            view = inflater.inflate(resId, null);
            {
                try {
                    mVideoView = (VideoView) view
                            .findViewById(R.id.playback_view);
                    String videourl = "sdcard/Download/WakaWaka.mp4";
                    mVideoView.requestFocus();
                    mVideoView.setVideoURI(Uri.parse(videourl));
                    mVideoView.start();
                } catch (Exception e) {
                    // TODO: handle exception
                }
            }
            break;
        case 2:
            resId = R.layout.video3;
            view = inflater.inflate(resId, null);

            break;
        }
        ((ViewPager) collection).addView(view, 0);

        return view;
    }

    @Override
    public void destroyItem(View arg0, int arg1, Object arg2) {
        ((ViewPager) arg0).removeView((View) arg2);
    }

    @Override
    public Parcelable saveState() {
        return null;
    }

    @Override
    public boolean isViewFromObject(View arg0, Object arg1) {
        return arg0 == ((View) arg1);
    }
}

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <VideoView
        android:id="@+id/playback_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
         />


</FrameLayout>

0 个答案:

没有答案