gpt4 book ai didi

java - LinearLayout WeightSum 不起作用

转载 作者:行者123 更新时间:2023-12-01 18:03:29 25 4
gpt4 key购买 nike

我有 6 个 TextView,用作我的音乐应用程序的按钮。我使用 layout_weight = 1 对其中 6 个进行权重求和,并且仍然有剩余空间。

这是我的 XML:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/layout_1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:weightSum="6"
tools:context="com.example.android.musicplayerapp.MainActivity">

<TextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center_vertical"
android:padding="16dp"
android:textColor="@android:color/white"
android:textStyle="bold"
android:text="Now playing"
android:background="#7FB3D5"/>

<TextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center_vertical"
android:padding="16dp"
android:textColor="@android:color/white"
android:textStyle="bold"
android:text="Songs"
android:background="#5499C7"/>

<TextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center_vertical"
android:padding="16dp"
android:textColor="@android:color/white"
android:textStyle="bold"
android:text="Artists"
android:background="#2980B9"/>

<TextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center_vertical"
android:padding="16dp"
android:textColor="@android:color/white"
android:textStyle="bold"
android:text="Playlists"
android:background="#2471A3"/>

<TextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center_vertical"
android:padding="16dp"
android:textColor="@android:color/white"
android:textStyle="bold"
android:text="Store"
android:background="#1F618D"/>

<TextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center_vertical"
android:padding="16dp"
android:textColor="@android:color/white"
android:textStyle="bold"
android:text="Search"
android:background="#154360"/>
</LinearLayout>

这里到底出了什么问题?感谢任何和所有的帮助。

最佳答案

设置父级的高度<LinearLayout>覆盖屏幕:

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/layout_1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="6"
tools:context="com.example.android.musicplayerapp.MainActivity">

关于java - LinearLayout WeightSum 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38812606/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com