Reputation:
This is my layout. I want these button should come at a center of screen either its is mobile or tablet. How can i achieve this. Please help me.
<?xml version="1.0" encoding="utf-8"?>
<ScrollView android:id="@+id/scrollView" xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@color/ubc_grey">
<RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content">
<TextView android:id="@+id/titleTextView" android:layout_width="fill_parent" android:layout_height="60dp"
android:background="@color/slate_grey" android:text="@string/title_home_map_view" android:textColor="@color/white"
android:gravity="center" android:textSize="20dp"/>
<LinearLayout android:id="@+id/linearLayout" android:layout_width="fill_parent" android:layout_height="fill_parent"
android:orientation="vertical" android:layout_centerInParent="true" android:layout_below="@+id/titleTextView"
android:layout_centerHorizontal="true" android:gravity="center" android:layout_marginTop="20dp">
<Button android:id="@+id/category" android:layout_width="250dp" android:layout_height="60dp"
android:text="@string/choose_category" android:textColor="@color/white" android:textSize="18dp"
android:layout_gravity="center"/>
<Button android:id="@+id/range" android:layout_width="250dp" android:layout_height="60dp"
android:text="@string/select_range" android:textColor="@color/white" android:layout_marginTop="20dp"
android:textSize="18dp" android:layout_gravity="center"/>
<Button android:id="@+id/useMyCurrentLocation" android:layout_width="250dp" android:layout_height="60dp"
android:layout_marginTop="20dp" android:textColor="@color/white" android:text="@string/button_use_my_current_location"
android:layout_gravity="center" android:textSize="18dp"/>
</LinearLayout>
</RelativeLayout>
</ScrollView>
This is what I'm trying to achieve
Upvotes: 1
Views: 123
Reputation: 23596
Please check this xml code. Here i have removed your color and the String Part.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center_vertical"
android:gravity="center_horizontal"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/linearLayout"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:gravity="center_vertical"
android:orientation="vertical" >
<Button
android:id="@+id/category"
android:layout_width="250dp"
android:layout_height="60dp"
android:text="choose_category"
android:textSize="18dp" />
<Button
android:id="@+id/range"
android:layout_width="250dp"
android:layout_height="60dp"
android:layout_marginTop="20dp"
android:text="select_range"
android:textSize="18dp" />
<Button
android:id="@+id/useMyCurrentLocation"
android:layout_width="250dp"
android:layout_height="60dp"
android:layout_marginTop="20dp"
android:text="button_use_my_current_location"
android:textSize="18dp" />
</LinearLayout>
</LinearLayout>
Also you can see the Screen shot attached below:
Hope you got the point.
feel free to comment.
Upvotes: 0
Reputation: 487
you have 4th line of
<RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content" lay>
You might need to remove the lay at the end of it :)
Cheers
Upvotes: 1
Reputation: 1426
xml for you:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="wrap_content"
android:background="@color/ubc_grey">
<LinearLayout
android:id="@+id/linearLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_centerInParent="true"
android:layout_marginTop="20dp"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:id="@+id/titleTextView"
android:layout_width="fill_parent"
android:layout_height="60dp"
android:background="@color/slate_grey"
android:gravity="center"
android:text="@string/title_home_map_view"
android:textColor="@color/white"
android:textSize="20dp" />
<Button
android:id="@+id/category"
android:layout_width="250dp"
android:layout_height="60dp"
android:text="@string/choose_category"
android:textColor="@color/white"
android:textSize="18dp" />
<Button
android:id="@+id/range"
android:layout_width="250dp"
android:layout_height="60dp"
android:layout_gravity="center"
android:layout_marginTop="20dp"
android:text="@string/select_range"
android:textColor="@color/white"
android:textSize="18dp" />
<Button
android:id="@+id/useMyCurrentLocation"
android:layout_width="250dp"
android:layout_height="60dp"
android:layout_gravity="center"
android:layout_marginTop="20dp"
android:text="@string/button_use_my_current_location"
android:textColor="@color/white"
android:textSize="18dp" />
</LinearLayout>
</RelativeLayout>
Upvotes: 0