den*_*izt 15 video android android-videoview
我目前正在尝试实施一个视频视频,该视频将显示特定位置的视频.我可以毫无问题地显示全屏视频.但是每当我试图在一个帧内显示该视频时(例如一个小矩形),我只能在该视图中显示一部分视频.我无法将视频放入该视图中.
我已经在android中查找了很多关于缩放视频的链接,但是我无法找到任何方法来做到这一点.有关该问题的任何帮助都会有所帮助.
我正在使用的是我有2个不同的课程.其中一个是我的视频活动类,另一个是帮助类:
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);
}
}
Run Code Online (Sandbox Code Playgroud)
该课程帮助我正确设置videoview的尺寸,但我无法使视频适合该区域.我的意思是我无法缩放视频以适应该区域.我不知道android是否自动缩放到给定的尺寸但我不能这样做.
愿这会帮助你...
public void onMeasure(int width, int height)
{
getHolder().setFixedSize(width, height);
forceLayout();
setMeasuredDimension(width, height);
invalidate();
}
Run Code Online (Sandbox Code Playgroud)
...并尝试相对布局
<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>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2300 次 |
| 最近记录: |