0

I have a layout that has 3 TextView's, one for title, one for date and one for a site name. I'd like the title to be above the date and site and the site to be right align to the date.

For some reason, the site TextView is a little higher than the date and I can't figure out why:

enter image description here

This is the layout code I'm using:

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@color/browser_bg"
    android:orientation="vertical">
        <ScrollView 
            android:id="@+id/webview"
            android:layout_width="fill_parent"
            android:layout_height="0dip"
            android:layout_weight="1" 
            android:paddingTop="10dp"
            android:paddingLeft="15dp"
            android:paddingRight="15dp"
            android:paddingBottom="10dp"
            >
             <RelativeLayout
                 android:layout_width="fill_parent"
                 android:layout_height="fill_parent"
                 android:padding="10dip"
                 android:orientation="horizontal"
                >     
                <TextView  
                    android:id="@+id/title"
                     android:layout_width="fill_parent"
                     android:layout_height="fill_parent"
                    android:textSize="18sp"
                    android:textStyle="bold"
                />
                <TextView  
                    android:id="@+id/date"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textSize="13sp"
                    android:textStyle="italic"
                    android:paddingTop="5dp"
                    android:layout_below="@id/title"
                    android:layout_alignParentLeft="true"
                />
                <TextView  
                    android:id="@+id/site"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:textSize="13sp"
                    android:gravity="right"
                    android:layout_alignParentRight="true"
                    android:layout_below="@id/title"
                />
            </RelativeLayout>
        </ScrollView>
</LinearLayout>
Kris B
  • 3,436
  • 9
  • 64
  • 106

2 Answers2

0

Wrap the date and site views with a RelativeLayout

Make the RelativeLayout android:layout_alignParentBottom="true" and android:gravity="center_vertical"

Like:

<RelativeLayout
    android:id="@id/bottom_row_container"
    android:layout_width="match_parent"
    android:layout_height="@dimen/SOME_NUMBER"
    android:layout_alignParentBottom="true"
    android:gravity="center_vertical" >
Gabe
  • 1,239
  • 1
  • 13
  • 20
  • 1
    This method may not work if you are trying to align fonts with different internal bottom 'padding'. See @Prachur comment regarding the use of the layout_alignBaseline tag for a more robust answer. – TheIT Dec 24 '13 at 00:23
0

TextViews automatically have some magic margin added to the top and bottom. The only way to truly work around it is to offset it with negative margin, but the problem with that is that it's dependent on your font size. You can also do android:includeFontPadding="false" and that should help a lot.

snotyak
  • 3,709
  • 6
  • 35
  • 52