简体   繁体   中英

Margin not working (xml)

I have a weird problem. The margin is not working correctly as it should be. It's actually not working all, I dont see any changes when I edit the margin bottom or margin top.

I want the copyright to stick to the bottom and I want my button to have some space from the textview.

My question: how do I let the textview copyright stick to the bottom + how do I create some space between the button and textview?

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" 
android:background="#ffffff"
android:padding="20dp"
>

<TextView 
    android:id="@+id/titel1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center_horizontal"
    android:text="ACT-test"
    android:textSize="20sp" 
    android:textStyle="bold" >
</TextView>

<TextView 
    android:id="@+id/tekst1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center_horizontal"
    android:text="Text."
    android:textSize="15sp" 
    >
</TextView>

<Button
android:id="@+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Doe de ACT-test"  
android:background="@drawable/yellow" 
style="@style/ButtonText"    
android:layout_marginTop="50dp" >
</Button>  

<Button
android:id="@+id/button2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Bekijk je ACT-scores"  
android:background="@drawable/blue" 
style="@style/ButtonText"  >
</Button>

<TextView 
    android:id="@+id/copyright"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center_horizontal"
    android:text="Copyright 2002."
    android:textSize="10sp" 
    android:paddingRight="20dp"
    android:paddingLeft="20dp"
    android:layout_marginBottom="10dp" >
</TextView>

 </LinearLayout>

Check this

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#ffffff"
    android:orientation="vertical"
    android:padding="20dp" >

    <TextView
        android:id="@+id/titel1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center_horizontal"
        android:text="ACT-test"
        android:textSize="20sp"
        android:textStyle="bold" >
    </TextView>

    <TextView
        android:id="@+id/tekst1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center_horizontal"
        android:text="Text."
        android:textSize="15sp" >
    </TextView>

    <Button
        android:id="@+id/button1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="50dp"
        android:text="Doe de ACT-test" >
    </Button>

    <Button
        android:id="@+id/button2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Bekijk je ACT-scores" >
    </Button>

    <TextView
        android:id="@+id/copyright"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:gravity="bottom|center_horizontal"
        android:paddingLeft="20dp"
        android:paddingRight="20dp"
        android:text="Copyright 2002."
        android:textSize="10sp" >
    </TextView>

</LinearLayout>

You will need to set the copyright Textview to

android:layout_alignParentBottom 

This should then allow you to set a margin on the bottom.

Which button, and which text view are you trying to put space between?

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