2012-06-08 76 views
-1

我有一对夫妇列表项。一个工作,另一个不工作,并且他们看起来非常相似。这真的应该是一个在XML文件中“发现差异”的游戏,但我不能在我的生活中找出错误。其中一个列表项是完美的,另一个拒绝证明布局右侧的某些视图,如xml中所示。这里是它们每个包含代码的样子。Android布局忽略引力属性

^list_view_item_2.xml:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:minHeight="?android:attr/listPreferredItemHeight" 
    android:padding="5dp"> 
    <TextView 
     android:id="@+id/item_text_product" 
     android:textSize="20sp" 
     android:layout_weight="1" 
     android:layout_height="wrap_content" 
     android:layout_width="0dp"/> 
    <TableLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content"> 
     <TableRow> 
      <TextView 
       android:id="@+id/item_text_total" 
       android:gravity="right" 
       android:textStyle="bold" 
       android:layout_span="2" 
       android:layout_height="wrap_content" 
       android:layout_width="wrap_content"/> 
     </TableRow> 
     <TableRow> 
      <TextView 
       android:id="@+id/item_text_units" 
       android:gravity="right" 
       android:textStyle="bold" 
       android:layout_height="wrap_content" 
       android:layout_width="wrap_content"/> 
      <TextView 
       android:id="@+id/item_text_uom" 
       android:gravity="right" 
       android:textStyle="bold" 
       android:layout_height="wrap_content" 
       android:layout_width="wrap_content"/> 
     </TableRow> 
     <TableRow> 
      <TextView 
       android:id="@+id/text_acog" 
       android:text="COG:" 
       android:gravity="right" 
       android:textStyle="bold" 
       android:layout_height="wrap_content" 
       android:layout_width="wrap_content"/> 
      <TextView 
       android:id="@+id/item_text_acog" 
       android:paddingLeft="1sp" 
       android:gravity="right" 
       android:textStyle="bold" 
       android:layout_height="wrap_content" 
       android:layout_width="wrap_content"/> 
     </TableRow> 
    </TableLayout> 
</LinearLayout> 

接下来的这个布局的作品之一。

^inventory_child_item.xml: 并且代码看起来相同,大部分...

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:minHeight="?android:attr/listPreferredItemHeight" 
    android:padding="5dp"> 
    <TextView 
     android:id="@+id/ici_site" 
     android:textSize="20sp" 
     android:layout_weight="1" 
     android:layout_height="wrap_content" 
     android:layout_width="0dp"/> 
    <TableLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content"> 
     <TableRow> 
      <TextView 
       android:id="@+id/ici_units" 
       android:gravity="right" 
       android:textStyle="bold" 
       android:layout_height="wrap_content" 
       android:layout_width="wrap_content"/> 
      <TextView 
       android:id="@+id/ici_uom" 
       android:paddingLeft="1sp" 
       android:gravity="right" 
       android:textStyle="bold" 
       android:layout_height="wrap_content" 
       android:layout_width="wrap_content"/> 
     </TableRow> 
     <TableRow> 
      <TextView 
       android:id="@+id/ici_total" 
       android:gravity="right" 
       android:textStyle="bold" 
       android:layout_span="2" 
       android:layout_height="wrap_content" 
       android:layout_width="wrap_content"/> 
     </TableRow> 
     <TableRow> 
      <TextView 
       android:id="@+id/ici_price" 
       android:gravity="right" 
       android:textStyle="bold" 
       android:layout_span="2" 
       android:layout_height="wrap_content" 
       android:layout_width="wrap_content"/> 
     </TableRow> 
    </TableLayout> 
</LinearLayout> 

回答

1

您需要设置match_parentListView

像:

android:layout_width="match_parent"

+0

忍不住 –

+0

lul。父视图已更改。危机避免了。 – moonlightcheese

1

MoonlightCheese,

唯一的区别我可以在你的代码中找到是:在工作的布局中,名为@+id/ici_uom的TextView的填充为1sp。因为没有合乎逻辑的理由,我可以弄清楚为什么这一行会导致任何不一致,因为它不应该这样做。您可能会更改此值,甚至将其添加到另一个列表中,并查看行为没有差异。因此,我倾向于认为,与自己或与父母的关系有所不同。

我这样说,因为这是绝对的事实,您的清单项目是正确的。看起来宽度在每个元素的基础上关闭。 LinearLayout中的fill_parent应该是该指标。我会重新分析列表本身以及潜在的填充视图的方式。

如果没有您的父母加价,很难确切地说出发生了什么以及为什么。这是因为我们不知道如何使用ListView,如果有多个,如果一个是ListActivity而另一个不是,或者它们是如何嵌套的。

基于在外观上的差异,我假设您有两个ListView S和为了进一步帮助您,我们需要标记为他们和他们的父母。没有标记,那就是我要告诉你看的地方。

希望这有助于

FuzzicalLogic

+0

你对男人的地方。它一直是父母。你救了我兄弟。 – moonlightcheese

0

我认为在textviews重力并不意味着你的情况下任何东西,因为layout_width是WRAP_CONTENT,这意味着,TextView的将是大如您文字是。如果你尝试在你的TableLayout中添加android:layout_gravity =“right”会怎么样。