gpt4 book ai didi

android - TextView 在 RelativeLayout 中离开屏幕

转载 作者:行者123 更新时间:2023-11-29 14:20:41 25 4
gpt4 key购买 nike

这是布局:

<?xml version="1.0" encoding="utf-8"?>

<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:columnCount="2"
android:rowCount="2"
android:rowOrderPreserved="true"
android:alignmentMode="alignMargins">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_row="0"
android:layout_column="0"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Test:" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_row="0"
android:layout_column="1"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="too long line too long line too long line too long line" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Test2:"
android:paddingRight="10dp"
android:layout_row="1"
android:layout_column="0" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_row="1"
android:layout_column="1"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Test line" />
</GridLayout>

这是发生的事情的截图:

TextView

如何防止第二个 TextView(屏幕截图中选择的那个)越过屏幕边界?

最佳答案

您可以通过为每个 TextView 提供 match_parent 宽度和适当的 layout_weight 来避免所有这些情况。下面的代码将为您提供您所需要的。享受吧!

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="3"
android:text="Test 1"/>

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="line too long line too long line too long line too long line too long "/>
</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="3"
android:text="Test 2"/>

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="line too long line too long line too long line too long line too long "/>
</LinearLayout>

</LinearLayout>

关于android - TextView 在 RelativeLayout 中离开屏幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21782608/

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