2015-08-15 51 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> 
相关问题