我想以编程方式设置 PercentRelativeLayout
内的 FrameLayout
的宽高比。
我已经在 xml
中尝试过,它正在工作:
<android.support.percent.PercentRelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="#000"
xmlns:android="http://schemas.android.com/apk/res/android">
<FrameLayout
app:layout_widthPercent="100%"
app:layout_aspectRatio="178%" //aspect ratio
android:orientation="vertical"
android:id="@+id/liveTV_frame"
android:layout_marginBottom="50dp"
android:layout_centerInParent="true"
android:background="@android:color/background_dark"
android:keepScreenOn="true">
</FrameLayout>
</android.support.percent.PercentRelativeLayout>
但我需要以编程方式设置它。
我怎样才能做到这一点?
最佳答案
PercentRelativeLayout layout = ...;
PercentRelativeLayout.LayoutParams layoutParams
= (PercentRelativeLayout.LayoutParams) layout.getLayoutParams();
layoutParams.getPercentLayoutInfo().aspectRatio = ...; // float value
layout.requestLayout();
关于java - 以编程方式设置 PercentageRelativeLayout 中的宽高比,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42897493/