nền tảng: đang phát triển trong Eclipse sử dụng SDK Android 16.Android VideoView không chơi Portrait Hướng
CÁC VẤN ĐỀ: Tôi có một yếu tố VideoView đó là nghĩa vụ để lấp đầy toàn bộ màn hình trong 480x800 (CHÂN DUNG ĐỊNH HƯỚNG) và nó chơi tốt, nhưng sẽ không định hướng chân dung. Nó dính trong chế độ phong cảnh và tỷ lệ khía cạnh được nghiêng để phù hợp theo cách đó.
GÌ Tôi đã cố gắng:
- sử dụng android: screenOrientation = "chân dung" trong manifest
- sử dụng android: định hướng = "thẳng đứng" trong các container và các VideoView tự
- sử dụng setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); ngay trước khi tôi gọi setContentView
- cố gắng để thiết lập chiều rộng bố trí và chiều cao để 480dpx800dp thay vì fill_parent
- cố gắng để thiết lập chiều rộng VideoView và chiều cao tới 480 x 800dp thay vì fill_parent
- tắt tự động xoay màn hình
THE XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="480dp"
android:layout_height="800dp"
android:background="#000000"
android:orientation="vertical" >
<VideoView
android:id="@+id/opening_video"
android:layout_width="480dp"
android:layout_alignParentRight="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"
android:layout_height="800dp"
android:orientation="vertical" />
<ImageButton
android:id="@+id/imageButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/transparent_button"
android:contentDescription="@string/back_button_desc"
android:background="@android:color/transparent" />
</RelativeLayout>
BỘ LUẬT:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
setContentView(R.layout.activity_start_screen);
VideoView videoView = (VideoView) findViewById(R.id.opening_video);
Uri pathToVideo = Uri.parse("android.resource://com.example.consumerengage/" + R.raw.opening_tablet);
videoView.setVideoURI(pathToVideo);
videoView.setOnPreparedListener(new OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
mp.setLooping(true);
}
});
videoView.requestFocus();
videoView.start();
// boolean isPlaying = videoView.isPlaying() ;
// videoView.stopPlayback();
// videoView.clearFocus();
addListenerOnButton();
}
câu hỏi: Không có gì tôi đã cố gắng đã thành công. Làm thế nào tôi có thể nhận được video 480x800 để phát theo hướng dọc?
Sau khi thay đổi XML của tôi thành cài đặt ở trên, video vẫn phát theo chiều ngang và không theo chiều dọc. –
@ RickS Sai lầm bạn đang thực hiện là xác định chiều cao cố định và chiều rộng cho bố cục và videoview của bạn. Chỉ cần sử dụng đối sánh mặc định của cha mẹ và chỉ cần viết android: screenOrientation = "portrait" vào hoạt động của tệp kê khai của bạn. –
xóa android: screenOrientation khỏi hoạt động của bạn trong tệp kê khai – AMD