【问题标题】:Android static fragment: When layout height is wrap_content then text don't show properlyAndroid 静态片段:当布局高度为 wrap_content 时,文本无法正确显示
【发布时间】: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


    【解决方案1】:

    在片段 2 中

    替换

    <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
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:weightSum="1">
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-03-08
      • 1970-01-01
      • 1970-01-01
      • 2019-02-05
      • 2021-08-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多