要设置FrameLayout的高度以匹配子组件之一,可以使用以下方法:
FrameLayout frameLayout = findViewById(R.id.frameLayout);
View childView = findViewById(R.id.childView);
int childHeight = childView.getHeight();
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) frameLayout.getLayoutParams();
layoutParams.height = childHeight;
frameLayout.setLayoutParams(layoutParams);
<FrameLayout
android:id="@+id/frameLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<View
android:id="@+id/childView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>
<FrameLayout
android:id="@+id/frameLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<View
android:id="@+id/childView1"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<View
android:id="@+id/childView2"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
</FrameLayout>
以上是设置FrameLayout高度以匹配子组件之一的几种方法。根据实际需求选择适合的方法进行设置。
没有搜到相关的文章