Joetjah
Joetjah

Reputation: 6132

Trouble with margins for Button

I'm having a LinearLayout with two TextView's and a Button.

I've styled the TextView's to be a little below other parts, by using layout_marginTop. This works correctly.

However, I want to move the button down more as well, but adapting the layout_marginTop property does not seem to help. All others (like padding) do work, but only the one I need doesn't work ofcourse.

<LinearLayout
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:weightSum="1">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:text="The value:"
        android:id="@+id/HeaderTextView"
        android:layout_gravity="left|top"
        android:layout_marginTop="20dip"
        android:fontFamily="sans-serif-light"
        android:textStyle="normal|bold"/>

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:text="-"
        android:id="@+id/ValueTextView"
        android:layout_below="@id/HeaderTextView"
        android:layout_marginTop="10dip"
        android:layout_gravity="left|center_vertical"
        android:fontFamily="sans-serif-thin" />

    <Button
        android:background="@drawable/red_button"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Reset Alarm"
        android:layout_below="@id/ValueTextView"
        android:layout_marginTop="120dip"
        android:id="@+id/getValueButton"
        style="@style/button_text"/>
</LinearLayout>

The top of the button is currently sticked against the bottom of the TextView above it. How come I can't move the button down?

Upvotes: 0

Views: 867

Answers (1)

Dhinakaran Thennarasu
Dhinakaran Thennarasu

Reputation: 3356

activity1.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/HeaderTextView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="left|top"
        android:layout_marginTop="20dip"
        android:fontFamily="sans-serif-light"
        android:text="Performance informatie"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:textStyle="normal|bold" />

    <TextView
        android:id="@+id/ValueTextView"
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:layout_gravity="left|center_vertical"
        android:layout_marginTop="10dip"
       android:text="-p789t89549"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <Button
        android:id="@+id/getValueButton"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Reset Alarm" 
        android:layout_gravity="bottom"/>

</LinearLayout>

activity2.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/layout1"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_marginLeft="20dp"
    android:orientation="vertical" >

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:layout_marginLeft="20dp"
        android:layout_weight="1"
        android:orientation="vertical" >

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Commando "
            android:textAppearance="?android:attr/textAppearanceLarge" />

        <Spinner
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:entries="@array/spinneritems"
            android:textAppearance="?android:attr/textAppearanceLarge" />

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Weger"
            android:textAppearance="?android:attr/textAppearanceLarge" />

        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceLarge" />

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Cel"
            android:textAppearance="?android:attr/textAppearanceLarge" />

        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="text "
            android:textAppearance="?android:attr/textAppearanceLarge" />

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Gewicht"
            android:textAppearance="?android:attr/textAppearanceLarge" />

        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="text "
            android:textAppearance="?android:attr/textAppearanceLarge" />

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Tolerantie"
            android:textAppearance="?android:attr/textAppearanceLarge" />

        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="text "
            android:textAppearance="?android:attr/textAppearanceLarge" />
    </LinearLayout>

    <Button
        android:id="@+id/share"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        android:text=" Uitvoeren" />

</LinearLayout>

Now this layout will include both and will act as your main layout.

<?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:orientation="horizontal" >

    <include layout="@layout/activity1" 
        android:layout_width="0dp"
        android:layout_weight="1"
        android:layout_height="match_parent"/>

    <include layout="@layout/activity2" 
        android:layout_width="0dp"
        android:layout_weight="1"
        android:layout_height="match_parent"/>

</LinearLayout>

Upvotes: 1

Related Questions