如何强制更改View的宽度和高度?

时间:2019-05-24 01:02:55

标签: android android-view

我正在使用Alpha Movie library

我有两个视频,第一个视频的高度大于宽度。第二个宽度比高度长。

将视频应用于“图书馆”的自定义视图时。视频的高宽比是固定的。

我对此进行了测试:

        <RelativeLayout
            android:layout_width="300dp"
            android:layout_height="300dp"
            android:layout_centerInParent="true"
            android:background="@color/assc_yellow">

            <com.alphamovie.lib.AlphaMovieView
                android:id="@+id/video_player"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                custom:accuracy="0.4"
                custom:alphaColor="#FDE958" />
        </RelativeLayout>

AlphaMoiveView的大小必须为300dp X 300dp。但是没有用。 似乎没有选择的余地。

我试图通过编程方式在Activity上更改它,如下所示:

alphaMovieView = findViewById(R.id.video_player)
alphaMovieView!!.layoutParams = RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT);

但是,它没有用。

1 个答案:

答案 0 :(得分:-1)

只需将其添加到根元素

xmlns:custom="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"

这应该有效

相关问题