Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I reduce the padding around text in Android xml layout?

I have 1 inch high text but the box of the view takes up 1.5 inches so there is 1/4 inch of black space above and below the white lettering. I want to reduce that 1/4 inch so that I can get 5 lines of text on my 6 inch screen instead of just 4. I can move them closer together with android:lineSpacingMultiplier=".66" but this just moves the boxes closer together and the 1/4 inch of black space covers the text of the nearby line. android:includeFontPadding="false" does nothing. Negative padding does nothing. Putting in android:lineSpacingExtra="-50sp" also just has the black margin cover the adjacent line of text. I want to get rid of the margin (actually, just most of it).

I have tried every option I can think of including the obvious ones of padding and margins and padding discussed above including zero and negative numbers. I can't find a simple diagram showing what controls the space in a view above the actual text.

How do I reduce this wasted space?

(my internet was down for the last 2 hours so it took me some time to respond. Sorry)

Here is my XML:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<TextView
    android:id="@+id/textTimer"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:includeFontPadding="false"
    android:text="10.01"
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:textSize="@dimen/font_size" />


<TextView
    android:id="@+id/textTimeToLine"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/textTimer"
    android:layout_centerHorizontal="true"
    android:includeFontPadding="false"
    android:text="10.02"
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:textSize="@dimen/font_size" />

<TextView
    android:id="@+id/textTimeToKill"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/textTimeToLine"
    android:layout_centerHorizontal="true"
    android:includeFontPadding="false"
    android:text="10.03"
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:textSize="@dimen/font_size" />

<TextView
    android:id="@+id/textTimeToPin"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/textTimeToKill"
    android:layout_centerHorizontal="true"
    android:includeFontPadding="false"
    android:text="10.03"
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:textSize="@dimen/font_size" />

<TextView
    android:id="@+id/textTimeToCB"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/textTimeToPin"
    android:layout_centerHorizontal="true"
    android:includeFontPadding="false"
    android:text="10.03"
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:textSize="@dimen/font_size" />

    <Button
    android:id="@+id/buttonMenu"
    style="?android:attr/buttonStyleSmall"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_alignParentTop="true"
    android:text="Menu" 
    android:onClick="onMenu"
    android:focusable="false"/>

</RelativeLayout>

In this screen shot, you can see that the border or margin around the fond is the area I want to reduce.

Screen Shot

like image 467
Allen Edwards Avatar asked Oct 07 '22 23:10

Allen Edwards


1 Answers

Some negative top and bottom margin. Things get messy though if you have fancy backgrounds.

like image 121
Ifor Avatar answered Oct 13 '22 01:10

Ifor