【问题标题】:Linear layout weightsum property is not working with Layout_height in android线性布局 weightsum 属性不适用于 android 中的 Layout_height
【发布时间】:2021-06-21 03:43:03
【问题描述】:

我的应用有一个textview,它的高度应该根据weight属性进行调整,但是它给出了红色错误。

代码是,

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:weightSum="10">
    <TextView
        android:textSize="50dp"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="3"
        android:text="@string/hello_pleasse_login"
        />

</LinearLayout>

screenshot

我也尝试过 android:layout_height="0dp" 和 android:layout_height="0" 但它不起作用, 请帮忙。

【问题讨论】:

    标签: android android-layout android-linearlayout


    【解决方案1】:

    只需将android:orientation="vertical" 添加到父布局即可。 LinearLayout 的默认方向是 Horizontal

    <LinearLayout android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:weightSum="10">
    <TextView
        android:textSize="50dp"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="3"
        android:text="@string/hello_pleasse_login"
        />
    </LinearLayout>
    

    【讨论】:

      【解决方案2】:

      默认linearLayout方向是水平的 把它改成垂直的 android:orientation="vertical"

      现在,你不会得到错误了

      【讨论】:

        猜你喜欢
        • 2014-11-21
        • 1970-01-01
        • 1970-01-01
        • 2012-10-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多