【问题标题】:Android VideoView how to scale as ImageView scale type fitXY?Android VideoView如何缩放为ImageView缩放类型fitXY?
【发布时间】:2015-01-26 16:42:22
【问题描述】:

我将一个 ImageView 和一个 VideoView 放在一个 RelativeLayout 中。 ImageView 可以通过scaleType="fitXY" 缩放以填充整个布局。但是,VideoView 没有类似的比例属性。顺便说一句,我通过设置setMediaController(null)隐藏了视频控件,只显示视频内容。是否可以在不保持纵横比的情况下缩放 VideoView? 这是布局示例。

<RelativeLayout
    android:layout_width="280dp"
    android:layout_height="200dp">

    <ImageView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:id="@+id/image"
        android:scaleType="fitXY" />

    <VideoView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:id="@+id/video"
        android:visibility="invisible"
        android:layout_centerInParent="true" />
</RelativeLayout>

【问题讨论】:

  • 尝试给定静态宽度和高度。
  • 它不起作用。我尝试设置&lt;VideoView android:layout_width="280dp" android:layout_height="200dp"/&gt;,但得到保持纵横比的结果。
  • 你试过我的回答了吗?
  • 是的。有用。谢谢。
  • 我已经实现了这个解决方案,它就像一个魅力:stackoverflow.com/a/59069292

标签: android scale android-videoview


【解决方案1】:

尝试将VideoView 放入RelativeLayout 并设置以下属性以全屏显示视频:

<VideoView
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   android:id="@+id/video"
   android:visibility="invisible"
   android:layout_alignParentBottom="true"
   android:layout_alignParentLeft="true"
   android:layout_alignParentRight="true"
   android:layout_alignParentTop="true"/>

注意:请根据您的要求设置可见度值。

【讨论】:

  • @Jones,很高兴为您提供帮助。
  • 在这一点上,我不敢问为什么......虽然有效!
【解决方案2】:

我的方法是重写VideoViewonMeasure方法

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    setMeasuredDimension(getDefaultSize(getSuggestedMinimumWidth(), widthMeasureSpec),
            getDefaultSize(getSuggestedMinimumHeight(), heightMeasureSpec));
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-07-28
    • 1970-01-01
    • 2013-01-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多