我有这个代码。所以我想通过scrollView中的高度在我的relativeLayout中设置高度。我可以通过scrollView的id设置高度吗?这是需要的,因为我有很多片段,但其中一个片段应该占据 scrollView 的高度(当虚拟键盘打开时)。
...
<ScrollView
android:id="@+id/scrollViewer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<FrameLayout
android:id="@+id/frameViewer"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<RelativeLayout
android:id="@+id/layoutViewer"
android:layout_width="match_parent"
android:layout_height="match_parent">
<WebView
android:id="@+id/webViewer"
android:layout_width="match_parent"
android:layout_height="match_parent">
</RelativeLayout>
</FrameLayout>
</ScrollView>
...
答案 0 :(得分:0)
ScrollView
的孩子(及其孩子)应该设置 layout_height="wrap_content"
以避免多次重新测量(更好的性能)
如果您想在内容高度较小的情况下填充整个 ScrollView
,请使用 fillViewport
xml attribute