Reputation: 23035
Please have a look at the following code
<?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="wrap_content"
android:layout_alignParentBottom="true"
android:background="#373734"
android:orientation="horizontal" >
<ImageView
android:id="@+id/backToLanguageSelectionButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="5dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="15dp"
android:paddingTop="5dp"
android:src="@drawable/thunderbolt" />
<ImageView
android:id="@+id/internetButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="5dp"
android:paddingTop="5dp"
android:src="@drawable/globe_small_2" />
<Button
android:id="@+id/giveUpButton"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="350dp"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:text="Button" />
</LinearLayout>
This is a common layout code which I am using for all the android activities. The problem is the button, I want it to move to the most right corner. Margin thing not seems to work properly because in different devices the button is in different places.
How can I move this to the most right corner which will be displayed same in all the devices?
Upvotes: 1
Views: 10332
Reputation: 844
It can be done with RelativeLayout
<Button
android:id="@+id/giveUpButton"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="350dp"
android:paddingBottom="5dp"
android:paddingTop="5dp"
android:text="Button"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true" />
Upvotes: 0
Reputation: 51
Use RelativeLayout and set its height to be as small as you want. This way a small part of your screen will be filled. When you use RelativeLayout, you can use android:layout_alignParentRight="true"
to put any item at right. Now, instead of button, you can use image and set its android:scaleType="centerInside"
if there are problems with the buttons scaling.
I was having the same problem as you and I sove it using RelativeLayout.
Upvotes: 0
Reputation: 80
User Relative layout instead. And apply android:layout_alignParentRight="true" to your Button.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#373734"
android:orientation="horizontal" >
<ImageView
android:id="@+id/backToLanguageSelectionButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="5dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="15dp"
android:paddingTop="5dp"
android:src="@drawable/social_share" />
<ImageView
android:id="@+id/internetButton"
android:layout_toRightOf="@+id/backToLanguageSelectionButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="5dp"
android:paddingTop="5dp"
android:src="@drawable/social_share" />
<Button
android:id="@+id/giveUpButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:text="Button" />
Upvotes: 2
Reputation: 1805
I believe you could add a view between your second ImageView and your button, and set it to layout_width="0dp", layout_weight="1". And remove the left margin of your button.
Upvotes: 4