我将 FrameLayout 的高度设置为 400,但仍为 64。
frame_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</FrameLayout>
MyClass.java
container = (FrameLayout) inflater.inflate(R.layout.frame_layout, scrollFrame, false);
scrollFrame.addView(container);
container.setLayoutParams(new
ScrollView.LayoutParams(ScrollView.LayoutParams.MATCH_PARENT, 400));
Log.d("Output", "FrameLayout Height: " + container.getHeight());
输出
FrameLayout Height: 64
即使我在xml中设置了layout_height="400",它仍然是64。我认为这与ScrollViews有关。(虽然我不能使用 LinearLayouts,因为它们会给我的代码带来许多其他问题。)我希望 FrameLayout 根据我放置在其中的视图动态调整大小。(LinearLayout 会自动调整大小,但它会调整到我试图显示的高度的 10 倍,使 ScrollView 太大;然后存在定位问题,因为 LinearLayout 试图强制在我试图手动排列的视图上定位)。