如何将视频视图显示到设备屏幕的一半? [英] How can i make my video view to half the screen of my device?

查看:177
本文介绍了如何将视频视图显示到设备屏幕的一半?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用视频视图和相对布局.该应用程序将仅以纵向模式运行.目前,我正在提供精确的dps以获得所需的大小.我想拥有的视频视图只有我的版面大小的一半.

I am using a video view and a relative layout. The app will only run in portrait mode. Currently, I am giving exact dps to get the desired size. What I would like to have is to get the video view with half the size of my layout.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:opencv="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_smile"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="MyActivity">

            <VideoView
                android:id="@+id/videoViewSmile"
                android:layout_width="match_parent"
                android:layout_height="300dp" />

</RelativeLayout>

推荐答案

首先,您可以使用名为DisplayMetricsandroid.Util类获得高度和宽度:

First thing, you can get both height and width using an android.Util class called DisplayMetrics :

DisplayMetrics displayMetrics = new DisplayMetrics();

然后将当前的显示信息插入声明的DisplayMetrics中:

And then insert the current display info into the declared DisplayMetrics :

getActivity().getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);

现在,您可以使用来获取屏幕的高度和宽度:

Now you can get the height and width of your screen by using :

displayMetrics.widthPixels // Width
displayMetrics.heightPixels // Height

以像素为单位,您可以通过以下方式更改高度:

It is measured in pixels, and you can change the height by :

videoView.getLayoutParams().height = displayMetrics.heightPixels / 2;

这篇关于如何将视频视图显示到设备屏幕的一半?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆