gpt4 book ai didi

android - 我如何在某个特定位置查看 videoview 内的视频?

转载 作者:可可西里 更新时间:2023-11-01 18:48:08 31 4
gpt4 key购买 nike

我目前正在尝试实现将在特定位置显示视频的视频 View 。我可以毫无问题地显示全屏视频。但是,每当我尝试在一个框架(例如一个小矩形)内显示该视频时,我只能在该 View 中显示一部分视频。我无法将视频放入该 View 。

我已经在寻找很多关于在 android 中缩放视频的链接,但是我找不到任何方法来做到这一点。有关该问题的任何帮助都会有所帮助。

我正在使用的是我有 2 个不同的类。其中一个是我的视频 Activity 类,另一个是辅助类:

public class VideoViewCustom extends VideoView {
private int mForceHeight = 0;
private int mForceWidth = 0;
public VideoViewCustom(Context context) {
super(context);
}
public VideoViewCustom(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}

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

public void setDimensions(int w, int h) {
this.mForceHeight = h;
this.mForceWidth = w;
}

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
setMeasuredDimension(mForceWidth, mForceHeight);
}
}

该类(class)帮助我正确设置视频 View 的尺寸,但我无法使视频适合该区域。我的意思是我无法缩放视频以适应该区域。我不知道 android 是否自动缩放到给定的尺寸,但我做不到。

最佳答案

希望这对你有帮助...

public void onMeasure(int width, int height)
{
getHolder().setFixedSize(width, height);
forceLayout();
setMeasuredDimension(width, height);
invalidate();
}

...然后试试 RelativeLayout

<RelativeLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >

<VideoView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentLeft="true"/>

</RelativeLayout>

关于android - 我如何在某个特定位置查看 videoview 内的视频?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10633970/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com