0

I'm working with a simple Android view (2 buttons). I've centered the buttons vertically but I noticed they are a little further down than directly center.

From what I can tell they are being centered using the space left over (after the header is put into the view). What I would prefer is that the header is not part of the view or that I could offset the centering by a specific dip (so it looks center instead of offset looking)

Anyone know if this is truly my issue or if you can offset a centered item?

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:id="@+id/widget30"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
>
        <Button
            android:id="@+id/loadViewBtn"
            android:layout_width="200dip"
            android:layout_height="80dip"
            android:text="View"
            android:textSize="18sp"
            android:layout_centerVertical="true"
            android:layout_centerHorizontal="true"
            >
    </Button>
    <Button
            android:id="@+id/loadUploadBtn"
            android:layout_width="200dip"
            android:layout_height="80dip"
            android:text="Upload"
            android:textSize="18sp"
            android:layout_below="@+id/loadViewBtn"
            android:layout_centerVertical="true"
            android:layout_centerHorizontal="true"
            >
    </Button>
</RelativeLayout>
Aurelio De Rosa
  • 21,856
  • 8
  • 48
  • 71
Toran Billups
  • 27,111
  • 40
  • 155
  • 268
  • Define "header" - I cannot see this in your XML. Is this the title bar of the activity you are referring to (which you can turn off) OR is it a header defined somewhere else in your XML? IF you are talking about the title bar then refer to this question http://stackoverflow.com/questions/2591036/how-to-hide-the-title-bar-for-an-activity-in-xml-with-existing-custom-theme – Graham Smith Jan 23 '12 at 00:06
  • I suppose I'm talking about the default title bar that's shown unless you do what @Edwin mentioned below – Toran Billups Jan 23 '12 at 00:12

2 Answers2

1

You could add a linearlayout on the bottom that is the same size as the header -- Height of status bar in Android

Or remove the header, see http://www.androidsnippets.com/how-to-make-an-activity-fullscreen

Community
  • 1
  • 1
Edwin Evans
  • 2,726
  • 5
  • 34
  • 47
1

My answer based upon comments is to hide the title bar, which is the same answers written in this Stackoverflow question How to hide the title bar for an Activity in XML with existing custom theme

My usual method to do this is either in the custom theme declaration OR manifest. I personally believe this is a better separation of concerns, as doing things to the UI in code that could be done within a defined theme just seems neater - especially if it has to be replicated in other activities.

Manifest Example

<activity android:name=".MainActivity"
      android:label="@string/app_name"
      android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen">

Theme Declaration Example

<style name="generalnotitle" parent="general">
    <item name="android:windowNoTitle">true</item>
</style>
Community
  • 1
  • 1
Graham Smith
  • 25,627
  • 10
  • 46
  • 69