我的理解是,wrap_content的內容需要儘可能多的空間。但是這不適用於TextViews嗎?不要將wrap_content調整爲字體的大小?
在以下佈局爲什麼當我將id爲real_status的TextView的字體更改爲24時,文本部分隱藏?我期待的是,由於包裝內容封閉的TextView,它將環繞24 sp並顯示文本。 18sp很好。
佈局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
>
<TextView
android:id="@+id/real_status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/full_display_name"
android:layout_alignParentRight="true"
android:layout_alignTop="@+id/full_display_name"
android:gravity="center_vertical"
android:textSize="24sp"
android:textStyle="bold"
tools:text="Active"
/>
<TextView
android:id="@+id/full_display_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_toLeftOf="@id/real_status"
android:gravity="center_vertical"
android:text="The real user status:"
android:textSize="16sp"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/full_display_name"
android:gravity="right"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:visibility="gone"
tools:text="Just a text view"
tools:visibility="visible" />
</LinearLayout>
</RelativeLayout>
</LinearLayout>
隨着18SP:
隨着24sp:
UPDATE:
之後我刪除了佈局頂部/底部並調整字體的答案,但現在我看到TextView與下一個小部件重疊。添加紅色背景更明顯。
我認爲,通過「growning」 TextView的其餘部分會向下移動,而不是重疊
'RelativeLayout'規則王牌大小值,特別是當你腳一個軸的兩端。你固定'real_status'的頂部和底部,所以'real_status'將是高度,而不是'wrap_content'。 – CommonsWare 2015-03-31 11:15:43
@CommonsWare:請參閱更新OP – Jim 2015-03-31 11:33:04
「我認爲通過」成長「的TextView其餘的將向下移動,而不是重疊」 - 你不使用'LinearLayout',大小移動部件。您正在使用'RelativeLayout',它與'LinearLayout'不同,很高興在W軸上重疊部件。如果你想'full_display_name'低於'real_status',在'full_display_name'上有'android:layout_below =「@ id/real_status'。 – CommonsWare 2015-03-31 11:38:02