Demeteor Demeteor - 3 days ago 4
Android Question

Layout Elements Covering corners

I am using AbsoluteLayout to try and cover the entire screen with the elements I want to add to create a "FullScreen" menu but it does not cover it. this is what I get. let me share my code as well , as youu see the Pink panel does not cover the corner of the screen why is that?
enter image description here

MainActivity xml

<?xml version="1.0" encoding="utf-8"?> <AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.apos.champquess.MainActivity">

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button"
android:id="@+id/button"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="77dp"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />

<ImageView
android:layout_width="404dp"
android:layout_height="550dp"
android:id="@+id/imageView"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentBottom="true"
android:layout_alignRight="@+id/button"
android:layout_alignEnd="@+id/button"
android:src="@color/colorAccent"
android:layout_below="@+id/button"
android:layout_x="280dp"
android:layout_y="78dp" />

<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New RadioButton"
android:id="@+id/radioButton"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="231dp"
android:layout_marginStart="231dp"
android:layout_x="150dp"
android:layout_y="73dp" />

<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New CheckBox"
android:id="@+id/checkBox"
android:layout_x="710dp"
android:layout_y="238dp" />




And MainActity Java

package com.example.apos.champquess;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//Remove title bar
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
//Remove notification bar
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
//set content view AFTER ABOVE sequence (to avoid crash)
this.setContentView(R.layout.activity_main);
setContentView(R.layout.activity_main);
}
}


EDIT: This is what I want it to look like (example)

enter image description here

Answer

quick answer here;

you use AbsoluteLayout This class was deprecated in API level 3. Use FrameLayout, RelativeLayout or a custom layout instead.

just take RelativeLayout as an example

ImageView is inside it and you have given width and height for it to possition it relatively

 android:layout_width="404dp"
 android:layout_height="550dp"

so it takes the size of that dimentions that's the reason it goes away the boundaries + you have padding s in your root tag AbsoluteLayout

there are couple of ways do you task if you want to give sizes manually give a small width like 75 dp or let me show you and example

Comments