A friendly place for programming greenhorns!
Big Moose Saloon
Search
|
Java FAQ
|
Recent Topics
Register / Login
Win a copy of
Arduino in Action
this week in the
General Computing
forum!
A special promo:
Enter your blog post or vote on a blogger to be featured in an upcoming Journal
JavaRanch
»
Java Forums
»
Mobile
»
Android
Author
how to put layout in middle of the screen?
chen young
Ranch Hand
Joined: Sep 09, 2005
Posts: 178
posted
Aug 03, 2010 12:50:52
0
Hi All,
How can I cause to the LinearLayout to be placed in the middle of the screen and not at the top ?
Thanks
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/appentry" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="fill_parent" android:gravity="center" android:background="@color/white"> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/leftlogo" android:layout_gravity="left" android:textColor="@color/red"/> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/rightlogo" android:layout_gravity="right" android:textColor="@color/white"/> </LinearLayout>
Ankit Garg
Saloon Keeper
Joined: Aug 03, 2008
Posts: 9191
2
I like...
posted
Aug 04, 2010 02:27:09
0
try
android:gravity="center_vertical"
on the
LinearLayout
...
[Edit] Since your buttons don't fill up the horizontal space, you'll need to align to center both vertically and horizontally. Try this:
android:gravity="center|center_vertical"
SCJP 6 | SCWCD 5 |
Javaranch SCJP FAQ
|
SCWCD Links
chen young
Ranch Hand
Joined: Sep 09, 2005
Posts: 178
posted
Aug 04, 2010 12:49:55
0
this is working for me ...
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="fill_parent" android:background="@color/white"> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/appentry" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="center" android:layout_centerInParent="true"> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/leftlogo" android:layout_gravity="left" android:textColor="@color/red"/> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/rightlogo" android:layout_gravity="right" android:textColor="@color/white"/> </LinearLayout> </RelativeLayout>
Thanks
I agree. Here's the link:
http://zeroturnaround.com/jrebel
- it saves me about five hours per week
subject: how to put layout in middle of the screen?
Similar Threads
ListView textColor
odd framelayout/surfaceview problem
Layout question.
how to call button inside a slidingDrawer
Need Help on the scrolling Bar in Android?
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter