私は、縦向きと横向きの2つの異なるレイアウトを持つアプリケーションを開発しています。
各レイアウトには2つのフラグメントが含まれています。1つのフラグメントには、インターネットからのビデオを再生するビデオビューが含まれています。向きを変えると、ビデオが再開します。
再起動せずにビデオを再生したい。
これが私のコードです:
**This is my main activity.**
------------------------
public class MainActivity extends Activity {
VIdeoFragment vfr = null;
ImageFragment ifr = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_activity);
vfr = new VIdeoFragment();
ifr = new ImageFragment();
FragmentTransaction ft1 = getFragmentManager().beginTransaction();
FragmentTransaction ft2 = getFragmentManager().beginTransaction();
ft1.add(R.id.upper_view, vfr, "Vfr");
ft2.add(R.id.down_view, ifr, "IFR");
ft1.commit();
ft2.commit();
}
}
**--------------------------------
VIdeoFragment**
public class VIdeoFragment extends Fragment {
VideoView vv,oldVV;
View view=null;
public static String movieUri = "http://www.prep-zone.com/androidVideo/College Admission from Prep Zone (HD).mp4";
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
Uri video = Uri.parse(movieUri);
vv.setVideoURI(video);
vv.start();
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
view = inflater.inflate(R.layout.video, container, false);
vv = (VideoView) view.findViewById(R.id.videoView1);
return view;
}
}
---------------------------------------------
ImageFragment
public class ImageFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
return inflater.inflate(R.layout.image, container,false);
}
}
-------------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/ic_action_search" />
</LinearLayout>
------------------------------
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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/videoView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" />
</LinearLayout>
-------------------------------------
portrait main xml
----------------
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/upper_view"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" >
</LinearLayout>
<LinearLayout
android:id="@+id/down_view"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" >
</LinearLayout>
</LinearLayout>
------------------------------------
landscape xml
----------------
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<LinearLayout
android:id="@+id/upper_view"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1">
</LinearLayout>
<LinearLayout
android:id="@+id/down_view"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1">
</LinearLayout>
</LinearLayout>
--------------------------------------------------------
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
================================================
please help.Thank you.