[英]relative layout not fitting the entire screen
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. 绿色背景是设备下的相对布局,即使我将布局设置为fill_parent或match_parent,它也不适合整个屏幕(之间有空白)。
here is the xml code of my app 这是我的应用程序的xml代码
<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>
I think with green color background, you are referring the RelativeLayout with android:id="@+id/relative_layout". 我认为在绿色背景下,您指的是带有android:id =“ @ + id / relative_layout”的RelativeLayout。 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. 要使整个背景变为绿色,您可以从容器相对布局中删除填充(android:paddingLeft =“ @ dimen / activity_horizontal_margin”等),也可以在容器相对布局中设置背景颜色。
Regards, 问候,
Paul 保罗
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 在RelativeLayout中
You root RelativeLayout
have default android padding, Thats the problem. 您的根RelativeLayout
具有默认的android填充,这就是问题所在。
<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
更改为
<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">
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.