gpt4 book ai didi

android - TextView 填充了 80% 的屏幕

转载 作者:行者123 更新时间:2023-11-29 18:23:31 28 4
gpt4 key购买 nike

我对 Android 非常陌生。

我想在 LinearLayout 中放置一个 TextView,它填充 LinearLayout 高度的 80%。

我该怎么做?或者如何分配宽度和高度的百分比?

谢谢。

最佳答案

像这样的布局会起作用。关键是 layout_weight 属性。 Android 的文档对于该属性不是很好。请注意,第二个 TextView(可以是任何东西)是必需的,否则第一个 TextView 将占据整个空间。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView android:layout_weight="0.8"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
android:background="#FFC300"
/>
<TextView android:layout_weight="0.2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="second text box"
/>
</LinearLayout>

关于android - TextView 填充了 80% 的屏幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3926135/

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