Reputation: 12725
Can you explain please why it isn't changing when I change gravity. First when I changed it position of button was changed but now I can't change position.
main.XML
<?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" >
<Button
android:id="@+id/button1"
android:layout_width="92dp"
android:layout_height="0dp"
android:layout_gravity="right"
android:layout_weight="1"
android:text="@string/button1" />
</LinearLayout>
Upvotes: 2
Views: 497
Reputation: 22493
set this property for related layout android:layout_width="match_parent" for LinearLayout (parent Layout)
Upvotes: 2
Reputation: 29199
You are setting gravity of button which will result in set your view's layout. for example if you have text on button, and you set gravity center, then it will center align the text into button, to set gravity of component into its parent, you need to set parent's gravity.
So Change your code to:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="right"
android:orientation="vertical" >
<Button
android:id="@+id/button1"
android:layout_width="92dp"
android:layout_height="0dp"
android:layout_weight="1"
android:text="@string/button1" />
</LinearLayout>
Upvotes: 1
Reputation: 383
My guess is that you need to set the property "layout_width" of the parent layout (i.e. the LinearLayout that contains the button) to fill_parent.
Upvotes: 0