android listview没有在drawelayout中显示,其中包含全屏视频

时间:2014-08-01 11:19:27

标签: android listview drawerlayout android-videoview

我想在用户触摸屏幕时将listview显示到我的视频播放器活动中, 我使用了DrawerLayout,但是当用户从屏幕的左边缘滑动手指时,我没有显示listview videoplayer.xml

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="fill_parent" 
android:layout_height="fill_parent">
<RelativeLayout 
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<VideoView>
<android:id="@+id/videoView1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentTop="true"
     >
</VideoView>
<ImageView
    android:id="@+id/imageView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:layout_marginLeft="20dp"
    android:src="@drawable/live" />
</RelativeLayout>
<LinearLayout
    android:id="@+id/drawer"
    android:layout_width="100dp"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:orientation="vertical">
<fragment
        android:id="@+id/fragment1"
        android:name="com.example.hls_06.MyListFragment1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1" />
</LinearLayout>
</android.support.v4.widget.DrawerLayout>

VideoPlayer.java

VideoView mVideoView;
MediaController mMediaController;
ProgressDialog pDialog;
String VideoUrl;
DrawerLayout drawerLayout;
View drawerView;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.requestWindowFeature(Window.FEATURE_NO_TITLE);


    setContentView(R.layout.videoplayer);
    drawerLayout = (DrawerLayout)findViewById(R.id.drawer_layout);
    drawerView = (View)findViewById(R.id.drawer);
    Bundle extra=getIntent().getExtras();
    Log.i("url fragment",extra.getString("urlSelectedFrgment"));
    VideoUrl=extra.getString("urlSelectedFrgment");
    getWindow().setFormat(PixelFormat.TRANSLUCENT);
    pDialog = new ProgressDialog(VideoPlayer.this);
    // Set progressbar title
    pDialog.setTitle("Android Video Streaming");
    // Set progressbar message
    pDialog.setMessage("Loading...");
    pDialog.setIndeterminate(false);
    pDialog.setCancelable(false);
    // Show progressbar
    pDialog.show();
    mVideoView = (VideoView) findViewById(R.id.videoView1);



    playVideo(VideoUrl);

    Log.i("play", Boolean.toString(mVideoView.isPlaying()));
    drawerLayout.setDrawerListener( new DrawerListener(){

        @Override
        public void onDrawerClosed(View drawerView) {

        }

        @Override
        public void onDrawerOpened(View drawerView) {

        }

        @Override
        public void onDrawerSlide(View drawerView, float slideOffset) {

        }

        @Override
        public void onDrawerStateChanged(int newState) {

        }});



}
public void playVideo(String VideoUrl){
    mMediaController = new MediaController(this);
    mVideoView.setVideoURI(Uri.parse(VideoUrl));

    mMediaController.setAnchorView(mVideoView);
    mVideoView.setMediaController(mMediaController);

    mVideoView.requestFocus();
    // mVideoView.start();
    mVideoView.setOnPreparedListener(new OnPreparedListener() {

        public void onPrepared(MediaPlayer mp) {
            pDialog.dismiss();
            mVideoView.start();
        }
    });

}

@Override
protected void onResume() {
    mVideoView.resume();
    super.onResume();
}

@Override
protected void onPause() {
    mVideoView.suspend();
    super.onPause();
}

@Override
protected void onDestroy() {
    mVideoView.stopPlayback();
    super.onDestroy();
}
@Override
public void onBackPressed()
{
    Intent intent=new Intent(VideoPlayer.this,MainActivity.class);
    startActivity(intent);
}

}

fragment.xml之

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<ListView
    android:id="@+id/android:list"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:drawSelectorOnTop="false" >
</ListView>

Fragment.java

public class MyListFragment1 extends ListFragment {

String[] values = new String[] { "arte", "BBC", "France2", "JSC", "TF1",
        "M6", "canal+", "wataniya" };
ListView listView;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    ListAdapter myListAdapter = new ArrayAdapter<String>(getActivity(),
            android.R.layout.simple_list_item_1, values);
    setListAdapter(myListAdapter);
}

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    ListView listView = getListView();
    listView.setBackgroundColor(Color.GRAY);
    listView.setDivider(new ColorDrawable(Color.WHITE));
    listView.setDividerHeight(3); // 3 pixels height
}

@Override
public void onListItemClick(ListView l, View v, int position, long id) {
    // TODO Auto-generated method stub

    String videoUrl = "";
    ((VideoPlayer) getActivity()).pDialog.show();
    if (getListView().getItemAtPosition(position).toString().equals("arte")) {
        videoUrl = "http://10.0.2.2:8080/WebApplication1/Le_b_tisier_enfants.mp4.mp4";
    } else if (getListView().getItemAtPosition(position).toString()
            .equals("BBC")) {
        videoUrl = "http://10.0.2.2:8080/WebApplication1/Le_b_tisier_enfants.mp4.mp4";
    }

    ((VideoPlayer) getActivity()).mVideoView.stopPlayback();
    ((VideoPlayer) getActivity()).playVideo(videoUrl);

}

}

0 个答案:

没有答案