简体   繁体   中英

Layout_margin is not working

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.

因为您将widthheight设置为wrap_content ,所以将它们的父LinearLayout特别更改为match_parent

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM