Reputation: 475
I want to use margin in my layout.But it's not working.This is my xml code:
<?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>
This is the result:
Why layout_margin is not working ?
Ps:I am using it with a listview.
Upvotes: 4
Views: 2878
Reputation: 2731
because you set width
and height
to wrap_content
, change them specially parent LinearLayout
to match_parent
Upvotes: 3