Android FrameLayout通过左上方的宽度和高度定位VideoView元素

时间:2016-04-27 22:07:39

标签: android android-linearlayout

我需要定位VideoView元素:

左:626dip 上:86dip 宽度:575度 身高:326dip

所以当apk开始时它在右上角...当我按下遥控器上的OK按钮时,它需要VideoView在FullScreen中(左:0,上:0,宽:100%x,高:100% y)的

我如何在xml文件中创建它?

我正在使用:

  android:layout_gravity="center"

以便将VideoView视频填充父级和视频调整为父级大小。

这是我尝试的代码,但它是以FullScreen为中心,当我按下OK按钮时,它是以SmallScreen为中心,并且不知道如何使用dp将其设置为Left和Top?

<?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" >

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

        <tv.danmaku.ijk.media.widget.VideoView
            android:id="@+id/videoViewRelative"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_gravity="center" />
    </FrameLayout>
</LinearLayout>

1 个答案:

答案 0 :(得分:0)

您只能使用XML创建一个状态。切换必须在代码中完成。 首先转储fill_parent,因为它已被弃用。然后,如果要动态缩放它,请将其与父项匹配或在XML中设置较小的大小。 然后使用视图动画进行动画转换。就像父母的宽度和高度一样,使用比例尺(将头部设置为0,0)或使用尺寸进行相应缩放。我将使用626 / parentWidth的计算比例缩放。 但是使用dips只能修复一个显示尺寸/密度