TextView在RelativeLayout中退出屏幕 [英] TextView go off screen in RelativeLayout
本文介绍了TextView在RelativeLayout中退出屏幕的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是布局:
<?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>
这是发生的情况的屏幕截图:
and here is the screenshot of what happens:
如何防止第二个TextView(在屏幕截图上选择的那个)越过屏幕边界?
How can I prevent second TextView (the one selected on the screenshot) from going over screen boundaries?
推荐答案
您可以通过为每个textview设置match_parent的宽度和适当的layout_weight来避免所有这些情况.以下代码将为您提供所需的确切信息.享受吧!
You can avoid all of this by giving each textview a width of match_parent and an appropriate layout_weight. The below code will give you exactly what you need. Enjoy!
<?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>
这篇关于TextView在RelativeLayout中退出屏幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文