我有一个 TextView,当没有要显示的文本时,它仍在占用空间。这仅发生在 OS 1.6 上。
当我的应用程序在 2.2 上运行时,TextView 的高度会收缩,因此它不会占用任何空间。
我可以在 TextView 中设置一些属性,因为当没有设置文本时它会折叠或消失吗?这是我的 XML 代码。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:layout_marginTop="3dp"
android:layout_marginRight="3dp"
android:background="#ff737373"
android:padding="3dp"
android:minWidth="64dp" >
<ImageView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:tag="tabImage"></ImageView>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="16sp"
android:tag="tabCaption"
android:textColor="#ffd9d9d9" />
</LinearLayout>
最佳答案
如果您想让 TextView 消失,如果它的文本是null
,那么使用android:visibility
或以编程方式使用textview。 setVisibility(View.INVISIBLE);
或 textview.setVisibility(View.GONE);
。
关于android - TextView占空间没有文字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7723920/