2

我的理解是,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:enter image description here

隨着24sp:enter image description here

UPDATE:
之後我刪除了佈局頂部/底部並調整字體的答案,但現在我看到TextView與下一個小部件重疊。添加紅色背景更明顯。
我認爲,通過「growning」 TextView的其餘部分會向下移動,而不是重疊 enter image description here

+0

'RelativeLayout'規則王牌大小值,特別是當你腳一個軸的兩端。你固定'real_status'的頂部和底部,所以'real_status'將是高度,而不是'wrap_content'。 – CommonsWare 2015-03-31 11:15:43

+0

@CommonsWare:請參閱更新OP – Jim 2015-03-31 11:33:04

+0

「我認爲通過」成長「的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

回答

0

是在wrap_content將被認爲需要儘可能多的空間。它也將應用於TextView。這裏的問題是您將android:layout_alignBottom="@+id/full_display_name"寫入real_status文本視圖。此屬性重寫wrap_content因此,從文本視圖中刪除allignBottom屬性。

UPDATE 爲了您的底部線佈局更新行

android:layout_below="@+id/full_display_name" 

android:layout_below="@+id/real_status" 
+0

請參閱OP – Jim 2015-03-31 11:31:43

0

刪除這兩個行會解決您的問題

android:layout_alignBottom="@+id/full_display_name"    
android:layout_alignTop="@+id/full_display_name" 
+0

中的更新請參閱OP – Jim 2015-03-31 11:31:46

+0

中的更新只是文本vie應該在real_status ==> android:layout_below =「@ + id/real_status – 2015-03-31 11:51:06

1

只要你患這個問題類型如果你理解得很好,你可以使用LiniarLayout。因爲wrap_content和match_parent在LiniarLayout中很容易處理。

讓瞭解它。(對於你的情況下).. 1.take 2 LiniarLayout(父母有verticle方向..) 我給標識LL1(水平)和ID LL2爲你的情況

2.in第一佈局2的TextView @ + ID/full_display_name@ + ID/real_status 在real_status在寬度已經match_parent所以它容易分裂親本(FILL_PARENT)並設置其機器人:比重= 「右」

3 .LiniarLayout,因爲它沒有涉及

查看belove的XML代碼...

<?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:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" > 

    <LinearLayout 
     android:id="@+id/LL1" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" > 

     <TextView 
      android:id="@+id/full_display_name" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="The real user status:" 
      android:textSize="16sp" /> 

     <TextView 
      android:id="@+id/real_status" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:gravity="right" 
      android:text="Active" 
      android:textSize="26sp" /> 
    </LinearLayout> 

    <LinearLayout 
     android:id="@+id/LL2" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/real_status" 
     android:gravity="right" > 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:gravity="center_vertical" 
      android:text="Just a text view" /> 
    </LinearLayout> 

</LinearLayout> 

它會幫助你你的GUI給bestView與文本任何規模大小

希望所有設備它幫助你