Why aren't these centered vertically? I am struggling with this and cannot make it work..
This is in a relativelayout and on the bottom of the display.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="46dp"
style="?headerfooter"
android:id="@+id/linlay2"
android:layout_below="@+id/ListView01"
android:gravity="center_vertical"
android:layout_alignBottom="@+id/mainrel">
<EditText
android:id="@+id/EditText_AddNewList"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:hint="@string/dialog_addnew_lists_listnamehint"
android:layout_centerVertical="true"
android:gravity="center_vertical"
android:layout_gravity="center_vertical"
android:layout_weight="1">
</EditText>
<Button
android:id="@+id/bSQLUpdate"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_centerVertical="true"
android:layout_gravity="center_vertical"
android:gravity="center_vertical"
android:layout_marginLeft="2dp"
android:layout_marginRight="2dp"
style="?button_add"/>
</LinearLayout>
Two suggestions:
1) What if you set the layout_height
of your LinearLayout
to wrap_content?
2) I suspect that your EditText
may be slightly too big (I've run into similar issues before) so if you change its height from wrap_content
to match_parent
you might have better luck.
fill_parent
and match_parent
resolve to the same thing. match_parent
is just a more accurate description. So, try fill_parent
! : - Jon O 2012-04-03 21:05
layout_height
(and potentially the layout_width
too) on the EditText
to 0dp
. Basically, this will make it use the layout_weight of 1 that you've assigned it in order to fill the remaining space after all else has been laid out - Jon O 2012-04-03 21:09
Have you tried using just "center" rather than "center_vertical"? Also, if you're looking to center things down an imaginary line running from the top of the screen to the bottom of the screen, center_horizontal would be what you're looking for.
Here's some code that places an item dead in the middle of the screen:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ProgressBar
android:id="@+id/electionsProgressBar"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="match_parent" android:layout_gravity="center_vertical|center_horizontal"/>
</LinearLayout>