2015-08-15 52 views
0

中指定的權重獲取空間我無法使用文本「15%」和「18%」的文本查看佔用父級水平線性佈局的50%空間儘管設置權重爲1,佈局寬度爲「0dp」以及其他所有可以完成的事情(設置父權重值爲2或設置字體較小)。以前類似問題中指定的解決方案中沒有一個解決了我的問題它以某種方式不會工作徹底搜索問題這個問題沒有解決方法這裏的工作是一個pastebin http://pastebin.com/FyzHX7Gn其中顯示部分代碼子元素不會根據android sdk

這裏是一個模擬器的快照我沒有電話測試所以不能說如果它在手機上工作或不。 enter image description here

回答

1

TextViews'父應該匹配整個顯示的寬度。這可以幫助你:

<LinearLayout 
    android:layout_row="2" 
    android:layout_column="1" 
    android:id="@+id/percentLinearLayout" 
    android:measureWithLargestChild="false" 
    android:weightSum="2" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal"> 

    <TextView           
     android:layout_width="0px" 
     android:layout_height="match_parent" 
     android:textAppearance="@android:style/TextAppearance.Holo.Medium" 
     android:text="@string/fifteen_percent" 
     android:id="@+id/percent15TextView" 
     android:layout_weight="1" /> 

    <TextView 
     android:layout_width="0px" 
     android:layout_height="match_parent" 
     android:textAppearance="?android:attr/textAppearanceMedium" 
     android:text="@string/eighteen_percent" 
     android:id="@+id/percentCustomTextView" 
     android:layout_weight="1" 
     android:numeric="integer" /> 
</LinearLayout> 
+0

有了這個第二TextView的熄滅界的Cuz線性佈局超出界限 –

+0

的你是什麼意思與「出界」?什麼邊界? – skywall

+0

以及它假設父母的寬度,即網格不是單元格(不確定),因此寬度變得更多的單元格,因爲匹配父母我認爲 –

1

嘗試這種情況:

<LinearLayout 
     android:id="@+id/percentLinearLayout" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_column="0" 
     android:layout_columnSpan="2" 
     android:layout_row="2" 
     android:orientation="horizontal" 
     android:weightSum="2"> 

     <TextView 
      android:layout_width="0px" 
      android:layout_height="match_parent" 
      android:textAppearance="@android:style/TextAppearance.Holo.Medium" 
      android:text="@string/fifteen_percent" 
      android:id="@+id/percent15TextView" 
      android:gravity="right" 
      android:layout_weight="1" /> 

     <TextView 
      android:id="@+id/percentCustomTextView" 
      android:layout_width="0px" 
      android:layout_height="match_parent" 
      android:layout_weight="1" 
      android:numeric="integer" 
      android:text="@string/eighteen_percent" 
      android:textAppearance="?android:attr/textAppearanceMedium" /> 
    </LinearLayout> 
相關問題