Reputation: 988
I have a button help with a margin right and left of 10dp. Then I add a button test to the left of a TextView
(centered horizontal), below the button help
and align left to the button help
.
The problem is that the button test is not exactly aligned to the button help
like TextView
test1
to the right of button help
.
What am I doing wrong?
Here is my layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#ffffff"
>
<TextView
android:id="@+id/mid"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="1"
android:gravity="center"
/>
<Button
android:id="@+id/help"
android:text="Help"
android:layout_width="match_parent"
android:layout_marginTop="35dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_height="wrap_content"/>
<Button
android:id="@+id/test"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/help"
android:layout_marginTop="5dp"
android:background="#87CEFF"
android:text="Test"
android:layout_toLeftOf="@id/mid"
android:layout_alignLeft="@id/help"
/>
<TextView
android:id="@+id/test1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/mid"
android:layout_alignBottom="@id/test"
android:layout_alignTop="@id/test"
android:layout_alignRight="@id/help"
android:text="test1\ntest2"
android:gravity="center"
android:textColor="#0000ff"
android:background="#00cc00"
/>
</RelativeLayout>
Upvotes: 0
Views: 49
Reputation: 227
There is nothing wrong in your code only one thing you have to add to your button test is android:background="@android:color/darker_gray" or any colour of your choice, android by default provides padding padding to button.
<Button
android:id="@+id/help"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="35dp"
android:background="@android:color/darker_gray"
android:text="Help" />
i have made necessary changes in above code try it hope it solves your issue
Upvotes: 0
Reputation: 65
wrap test button and textview in a relative layout and align parent right and left each one.
Upvotes: 0
Reputation: 185
i think thats just the background of the help-button. if you use a custom background for it aswell, it will fill up all his space.
Upvotes: 1