Question

Following is my xml I want to set button1 to left centrally vertical and button2 to right centrally vertical but for me android:layout_gravity="center_vertical|right" is not working what is the wrong? I know that i can achieve this by applying by using padding or margin but I won't know that why it is not working. How should I make it work?

<?xml version="1.0" encoding="utf-8"?>
<HorizontalScrollView 
    xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent">
    <FrameLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Button1"
                android:layout_gravity="center_vertical"
                />
        <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Button2"
                android:layout_gravity="center_vertical|right"/> 
        <RelativeLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent">
        </RelativeLayout>
    </FrameLayout>
  </HorizontalScrollView>
Was it helpful?

Solution

Here your problem is as you are using HorizontalScrollView , as a result FrameLayout is not being able to make its width to fill_parent.If you remove the HorizontalScrollView you will get the desired result I think.

OTHER TIPS

Yes, if you replace HorizontalScrollView with LinearLayout, then you will see the desired effect.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top