0

the green coloured background is the relative layout under device, its not fitting the entire screen (there is a white space in between )even though i have made the layout to be fill_parent or match_parent. enter image description here

here is the xml code of my app

 <RelativeLayout   
 xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:tools="http://schemas.android.com/tools"   
 android:layout_width="fill_parent"
 android:layout_height="fill_parent" 
 android:paddingLeft="@dimen/activity_horizontal_margin"
 android:paddingRight="@dimen/activity_horizontal_margin"
 android:paddingTop="@dimen/activity_vertical_margin"
 android:paddingBottom="@dimen/activity_vertical_margin" 
 tools:context=".MainActivity">

 <RelativeLayout
    android:id="@+id/relative_layout"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_alignParentRight="true"
    android:layout_alignParentEnd="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_alignParentTop="true"
    android:layout_alignParentBottom="true">

    <RelativeLayout
        android:layout_width="300dp"
        android:layout_height="300dp"
        android:layout_centerVertical="true"
        android:layout_centerHorizontal="true"
        android:id="@+id/relativeLayout">

        <Button
            style="?android:attr/buttonStyleSmall"
            android:layout_width="100dp"
            android:layout_height="100dp"
            android:id="@+id/button"
            android:layout_alignParentTop="true"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true" />

        <Button
            style="?android:attr/buttonStyleSmall"
            android:layout_width="100dp"
            android:layout_height="100dp"
            android:id="@+id/button2"
            android:layout_alignParentTop="true"
            android:layout_alignParentRight="true"
            android:layout_alignParentEnd="true" />

        <Button
            style="?android:attr/buttonStyleSmall"
            android:layout_width="100dp"
            android:layout_height="100dp"
            android:id="@+id/button3"
            android:layout_alignParentBottom="true"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:singleLine="false" />

        <Button
            style="?android:attr/buttonStyleSmall"
            android:layout_width="100dp"
            android:layout_height="100dp"
            android:id="@+id/button4"
            android:layout_alignParentBottom="true"
            android:layout_alignRight="@+id/button2"
            android:layout_alignEnd="@+id/button2" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/textView"
            android:textStyle="bold"
            android:layout_below="@+id/button"
            android:layout_above="@+id/button3"
            android:layout_toRightOf="@+id/button"
            android:layout_toLeftOf="@+id/button2"
            android:layout_toStartOf="@+id/button2" />

        <Button
            style="?android:attr/buttonStyleSmall"
            android:layout_width="100dp"
            android:layout_height="100dp"
            android:text="start"
            android:id="@+id/button6"
            android:layout_above="@+id/button3"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true" />

        <Button
            style="?android:attr/buttonStyleSmall"
            android:layout_width="100dp"
            android:layout_height="100dp"
            android:text="ok"
            android:id="@+id/button5"
            android:layout_centerVertical="true"
            android:layout_alignRight="@+id/button4"
            android:layout_alignEnd="@+id/button4" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/textView2"
            android:textStyle="bold"
            android:layout_above="@+id/textView"
            android:layout_toRightOf="@+id/button"
            android:layout_alignParentTop="true"
            android:layout_alignRight="@+id/textView"
            android:layout_alignEnd="@+id/textView" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/textView3"
            android:textStyle="bold"
            android:layout_alignParentBottom="true"
            android:layout_toRightOf="@+id/button3"
            android:layout_below="@+id/textView"
            android:layout_toLeftOf="@+id/button4"
            android:layout_toStartOf="@+id/button4" />
    </RelativeLayout>

    <Button
        style="?android:attr/buttonStyleSmall"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="INSTRUCTIONS"
        android:id="@+id/button7"
        android:textStyle="bold"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true" />

    <TextView
        android:layout_width="100dp"
        android:layout_height="50dp"
        android:id="@+id/textView5"
        android:textStyle="bold"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true"
        android:layout_alignParentTop="true"
        android:layout_alignBottom="@+id/button7"
        android:layout_toRightOf="@+id/button7"
        android:layout_toEndOf="@+id/button7" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="TIME"
        android:textSize="30dp"
        android:textStyle="bold"
        android:id="@+id/textView6"
        android:layout_above="@+id/relativeLayout"
        android:layout_centerHorizontal="true" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="SCORE"
        android:textStyle="bold"
        android:textSize="30dp"
        android:id="@+id/textView7"
        android:layout_below="@+id/relativeLayout"
        android:layout_centerHorizontal="true" />

</RelativeLayout>
</RelativeLayout>
murali kurapati
  • 1,510
  • 18
  • 23

3 Answers3

2

I think with green color background, you are referring the RelativeLayout with android:id="@+id/relative_layout". If that is true, then you are getting the white space because of the padding mentioned in the container relative layout. The root (the container for all other) relative layout is fitting the entire screen.

To make the entire background green, you can either remove the padding (android:paddingLeft="@dimen/activity_horizontal_margin" etc.) from the container relative layout or set the background color in the container relative layout.

Regards,

Paul

Paul
  • 506
  • 4
  • 10
1

just remove

 android:paddingLeft="@dimen/activity_horizontal_margin"
 android:paddingRight="@dimen/activity_horizontal_margin"
 android:paddingTop="@dimen/activity_vertical_margin"
 android:paddingBottom="@dimen/activity_vertical_margin" 

in RelativeLayout

Kastriot Dreshaj
  • 1,121
  • 6
  • 16
0

You root RelativeLayout have default android padding, Thats the problem.

<RelativeLayout   
 xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:tools="http://schemas.android.com/tools"   
 android:layout_width="fill_parent"
 android:layout_height="fill_parent" 
 android:paddingLeft="@dimen/activity_horizontal_margin"
 android:paddingRight="@dimen/activity_horizontal_margin"
 android:paddingTop="@dimen/activity_vertical_margin"
 android:paddingBottom="@dimen/activity_vertical_margin" 
 tools:context=".MainActivity">

Change this main RelativeLayout to

<RelativeLayout   
 xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:tools="http://schemas.android.com/tools"   
 android:layout_width="fill_parent"
 android:layout_height="fill_parent" 
 tools:context=".MainActivity">
Vettiyanakan
  • 7,957
  • 6
  • 37
  • 55