如何在Android中将一个布局的高度设置为另一个布局的高度?

时间:2021-03-25 07:06:19

标签: android xml android-layout kotlin binding

我有这个代码。所以我想通过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>
...

1 个答案:

答案 0 :(得分:0)

ScrollView 的孩子(及其孩子)应该设置 layout_height="wrap_content" 以避免多次重新测量(更好的性能)

如果您想在内容高度较小的情况下填充整个 ScrollView,请使用 fillViewport xml attribute

相关问题