简体   繁体   English

如何更改SurfaceView的宽度和高度?

[英]How to change SurfaceView width and height?

I have a SurfaceView in ConstraintLayout. 我在ConstraintLayout中有一个SurfaceView。
I changed SurfaceView width and height, but only height is changed. 我更改了SurfaceView的宽度和高度,但只更改了高度。

How to change SurfaceView width? 如何更改SurfaceView宽度?

this is my activity.xml. 这是我的activity.xml。

    <android.support.constraint.ConstraintLayout
      xmlns:android = "http://schemas.android.com/apk/res/android"
      xmlns:tools = "http://schemas.android.com/tools"
      android:layout_width = "match_parent"
      android:layout_height = "match_parent"
      xmlns:app = "http://schemas.android.com/apk/res-auto"
      tools:context = ".MainActivity"
    >
    <SurfaceView
        android:id="@+id/surface_play"
        android:layout_width = "0dp"
        android:layout_height = "200dp"
        app:layout_constraintTop_toTopOf ="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"        />

    <Button
        android:id="@+id/btn_play"
        android:layout_width = "wrap_content"
        android:layout_height = "wrap_content"
        android:text="play"
        app:layout_constraintTop_toBottomOf="@+id/surface_play"
        app:layout_constraintStart_toStartOf="parent"        />

    <Button
        android:id="@+id/btn_stop"
        android:layout_width = "wrap_content"
        android:layout_height = "wrap_content"
        app:layout_constraintTop_toTopOf="@+id/btn_play"
        app:layout_constraintStart_toEndOf="@+id/btn_play"        
        android:text="stop"        />    
</android.support.constraint.ConstraintLayout>

this is surfaceChangedMethod. 这是surfaceChangedMethod。

     @Override
    public void surfaceChanged ( SurfaceHolder holder , int format , int width , 
    int height ) {

    android.view.ViewGroup.LayoutParams lp = surfaceView.getLayoutParams();
    lp.width = 1000; // required width
    lp.height = 1000; // required height
    surfaceView.setLayoutParams(lp);
}

I solve myself. 我自己解决。 Change a SurfaceView's attribute 更改SurfaceView的属性

android:layout_width = "0dp"

to

android:layout_width = "wrap_content" 

than it works. 比它的作品。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何更改JTextField的宽度和高度? - How do you change the width and height of JTextField? 如何以编程方式更改视图的宽度和高度? - How to change width and height of a view programmatically? 如何在CodenameOne中更改组件的大小(宽度和高度) - How is possible to change size(width and height) of the component in codenameone 如何使用java在给定新高度和宽度的情况下更改图像大小? - How to change the size of image with given new height and width using java? 如何使用Java更改HTML文件的宽度和高度 - How to change the width and height of an html file using java 如何通过鼠标单击按钮来更改小程序的大小(宽度x高度)? - how to change the size(Width x Height) of applet by mouse click on the Button? 如何测量宽度和高度,然后在添加视图之前更改参数? - How to measure width and height, then change parameters before adding view? 如何在不更改高度的情况下更改矩形形状的宽度 - How to change width of rectangle shape without changing height 如何更改进度条的大小(宽度和高度)以适合所有线性布局? - How to change the size (width and height) of progressbar to fit all in linearlayout? 宽度和高度是否随方向而变化? - Does the Width and Height change with orientation?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM