首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在纵向模式下用全屏视频制作视频

在纵向模式下用全屏视频制作视频
EN

Stack Overflow用户
提问于 2016-09-30 02:06:42
回答 3查看 2.6K关注 0票数 0

我有一个视频在一个视频播放和循环作为我的登录/注册活动的背景。视频播放和循环很好,除非它不覆盖整个屏幕。活动锁定在纵向模式,但视频只显示在屏幕的下半部分(好像在景观模式)。videoview本身确实覆盖了整个屏幕。这是我目前的密码。

代码语言:javascript
复制
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_launcher);

    VideoView videoView = (VideoView) findViewById(R.id.launcherVideo);
    Uri src = Uri.parse("android.resource://com.package/raw/video");
    videoView.setVideoURI(src);

    videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {

        @Override
        public void onPrepared(MediaPlayer mp) {

            mp.setVolume(0, 0);
            mp.setLooping(true);
        }
    });

    //videoView.setMediaController(new MediaController(this));

    videoView.start();
}

这是我的xml

代码语言:javascript
复制
<VideoView
    android:id="@+id/launcherVideo"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_above="@+id/linearLayout" />

如何使视频全屏在任何大小的设备上?

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2016-09-30 04:25:57

您可以尝试使用TextureView而不是VideoView,这是回答描述的。

票数 -1
EN

Stack Overflow用户

发布于 2016-09-30 04:59:52

由于没有看到整个布局xml,我想可能会有所帮助。

尝试用一个VideoView包装您的RelativeLayout,并将它对齐到父程序:

代码语言:javascript
复制
<VideoView
    android:id="@+id/launcherVideo"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentTop="true"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true">
票数 2
EN

Stack Overflow用户

发布于 2018-09-14 11:43:01

代码语言:javascript
复制
  <RelativeLayout
            android:id="@+id/video_layout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_below="@+id/progress_limit">

            <com.example.FullScreenVideoView
                android:id="@+id/video_view"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_alignParentTop="true"
                android:layout_alignParentBottom="true"
                android:layout_alignParentEnd="true"
                android:layout_alignParentStart="true"/>
            <ProgressBar
                android:id="@+id/progress"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:indeterminate="false"
                android:layout_centerInParent="true"
                 />
        </RelativeLayout>

也可以使用它对我有用的代码

代码语言:javascript
复制
public class FullScreenVideoView extends VideoView {
    public FullScreenVideoView(Context context) {
        super(context);
    }

    public FullScreenVideoView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public FullScreenVideoView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec){
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        setMeasuredDimension(widthMeasureSpec, heightMeasureSpec);
    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39782591

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档