1

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

Demeteor
  • 1,193
  • 2
  • 17
  • 33
  • "Pink panel does not cover the corner of the screen " can you explain a bit what actually you need to do? maybe with a sketch diagram – Charuක Dec 01 '16 at 13:02
  • Hey @CharukaSilva I have added a screenshot of the desired effect at the bottom of the post – Demeteor Dec 01 '16 at 13:09

1 Answers1

1

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 if you want to give sizes manually give a small width like 75 dp

there are couple of ways do you task

but first do not try to give sizes manually then it will display differently in different screen sizes , but for a single screen you can give these values. otherwise you need to use a value based on ratio. learn about layout_weight and `

What does android:layout_weight mean?

` and how to use it, a simple example -->Android Layout - layoutweight and weightsum or pragmatically you can give sizes based on ratio

// get screen sises 
     Display display = this.getWindowManager().getDefaultDisplay();
            Point size = new Point();
            display.getSize(size);
            int screenY = size.y;
            int screenX = size.x; 

RelativeLayout.LayoutParams yourView= new RelativeLayout.LayoutParams(screenX, 270 * screenY / 1920);
        yourView.topMargin = 0;
        yourView.leftMargin = 125 * screenX / 1080;
        imgPoints.setLayoutParams(yourView);

and learn about RelativeLayout and LinearLayout behaviors as well

Community
  • 1
  • 1
Charuක
  • 12,953
  • 5
  • 50
  • 88
  • So this works like css ? should I go around using the layouts with the same logic ? – Demeteor Dec 01 '16 at 13:20
  • @ Demeteor try it out ur self and if you find it hard or if there is any issue leave a comment below so i can help you out – Charuක Dec 01 '16 at 14:19