2014-10-01 59 views
0

我想用我的保证金它layout.But不是working.This是我的XML代码:Layout_margin不工作

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:orientation="vertical"> 


<LinearLayout 
    android:id="@+id/blocks" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:background="@drawable/mes7" 
    android:layout_marginRight="6dp" 
    android:layout_marginTop="6dp" 
    android:clickable="false"> 
<TextView 
    android:id="@+id/message" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_gravity="left" 
    android:layout_marginLeft="4dp" 
    android:layout_marginRight="6dp" 
    android:layout_marginTop="3dp" 
    android:gravity="left" 
    android:paddingLeft="5dp" 
    android:paddingRight="5dp" 
    android:paddingTop="1dp" 
    android:text="Test Message" 
    android:textSize="12dp"/> 

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_gravity="right|bottom" 
    android:text="19:40" 
    android:textSize="8dp"/> 
</LinearLayout> 
</LinearLayout> 

这是结果:

enter image description here

为什么layout_margin不管用 ?

Ps:我正在使用它与一个列表视图。

+0

让你顶的LinearLayout有'的android:layout_width = “match_parent”' – dharms 2014-10-01 20:40:15

+0

我尝试过,但没有奏效。 – 2014-10-01 20:45:20

+0

实际上你不需要顶部的LinearLayout。删除它并将布局宽度添加到剩余的LinearLayout。 – dharms 2014-10-01 20:46:45

回答

0

因为你设置widthheightwrap_content,改变他们专门父LinearLayoutmatch_parent

+0

我做到了:http://pastebin.com/GTq5vm9c但仍然一样。 – 2014-10-01 20:43:49

+0

为另一个LinearLayout做它也 – MHP 2014-10-01 20:45:22

+0

http://pastebin.com/unznCRfF仍然一样。 – 2014-10-01 20:46:43