【发布时间】:2020-04-02 08:45:42
【问题描述】:
尝试使用带有layout_height="wrap_content" 的静态片段时,UI 未按预期显示。
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment
android:id="@+id/fragment1”
android:name=“…..”
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/fragment2" />
<fragment
android:id="@+id/fragment2”
android:name=“….”
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" />
</RelativeLayout>
Fragment2 有这样的布局
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:weightSum="1">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.7">
<WebView
android:id="@+id/webview”
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.3"
android:orientation="vertical">
<Button
android:id="@+id/btn1”
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button
android:id="@+id/btn”2
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
当尝试用文本重新加载 WebView 中的内容时
web.loadData("I confirmed that I have read and understand all the materialfasd<br>fasd<br>fase<br>....fasd", "text/html; charset=utf-8", null);
它在设备中看起来像这样
有什么办法可以解决这个问题吗?
【问题讨论】:
标签: android xml android-layout fragment