Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7823395
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T08:13:53+00:00 2026-06-02T08:13:53+00:00

I have the following XML: <?xml version=1.0 encoding=utf-8?> <RelativeLayout android:id=@+id/rl android:background=@color/red android:layout_width=fill_parent android:layout_height=fill_parent xmlns:android=http://schemas.android.com/apk/res/android>

  • 0

I have the following XML:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:id="@+id/rl"
    android:background="@color/red"
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"
    xmlns:android="http://schemas.android.com/apk/res/android">
    <WebView xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/webview"
        android:layout_width="10dp"
        android:layout_height="10dp" />
</RelativeLayout>

When I call:

view.layout(50, 50, 1024 - 50, 600 - 50);

from onCreate() and onStart(), it has no effect. But when I add the same call to shouldOverrideKeyEvent() and press a key, it works. I think it’s because my settings are being overriden by XML’s ones. So, the question is: when should I call layout() as soon as possible, but after android:layout_width=”10dp” and android:layout_height=”10dp” are already applied.

UPDATE

I use the solution by blessenm.

private class LayoutListener implements OnGlobalLayoutListener
{
    public void onGlobalLayout()
    {
        Display display = getWindowManager().getDefaultDisplay();
        int screenWidth = display.getWidth();
        int screenHeight = display.getHeight();

        // Workaround for a 'fill_parent' bug on my tablet (Kindle Fire).
        _WebView.layout(0, 0, screenWidth, screenHeight);
        _WebView.loadUrl("http://192.168.1.2");
        //_Layout.getViewTreeObserver().removeGlobalOnLayoutListener(this); 
    }
}

If I comment removeGlobalOnLayoutListener() out, it stops working. Debugger shows it’s called twice, so I guess the second call only actually sets the size. So, I’ve decided not to remove the listener (if it’s called 2 times, that’s not a performance killer). It’d seemed OK, until I realized it’s called whenever I click a permanent bottom-bar, causing toolbar appearance. And since I load a site after setting layout, it’s being reloaded every time. And I have to load the site only when the view’ size is correct, because a server sends content, specially optimized for the given size.

That’s why I cannot leave the listener and should remove it. But when? Just count to 2? Will it work on every device/Android version? Why does it work for the second call, but not for the first?

Regards,

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T08:13:54+00:00Added an answer on June 2, 2026 at 8:13 am

    I think its because in the onCreate event the layouts haven’t been drawn or measured yet. So If you try to call layout in that event it wont have an impact. Try to put your code in the viewtreeobserver, it might work.

    Add this to your activity’s onCreate

    ViewTreeObserver vto        =   layout.getViewTreeObserver(); 
        vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() { 
        @Override 
        public void onGlobalLayout() { 
            view.layout(50, 50, 1024 - 50, 600 - 50);
            layout.getViewTreeObserver().removeGlobalOnLayoutListener(this); 
        } 
    }); 
    

    where layout can be your parent or outer layout.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following layout: <?xml version=1.0 encoding=utf-8?> <RelativeLayout android:id=@+navigate/RLayout android:layout_width=fill_parent android:layout_height=fill_parent android:background=#ABABAB xmlns:android=http://schemas.android.com/apk/res/android
I have used the following in android manifest. <?xml version=1.0 encoding=utf-8?> <RelativeLayout xmlns:android=http://schemas.android.com/apk/res/android xmlns:ads=http://schemas.android.com/apk/lib/com.google.ads
I have the following layout buttons.xml <?xml version=1.0 encoding=UTF-8?> <RelativeLayout xmlns:android=http://schemas.android.com/apk/res/android android:id=@+id/buttonsLayout android:layout_width=fill_parent android:layout_height=wrap_content
I have the following layout file: <?xml version=1.0 encoding=utf-8?> <RelativeLayout xmlns:android=http://schemas.android.com/apk/res/android android:layout_width=fill_parent android:layout_height=wrap_content android:background=#FF0000
I have the following layout defined in XML: <?xml version=1.0 encoding=utf-8?> <RelativeLayout xmlns:android=http://schemas.android.com/apk/res/android android:layout_height=wrap_content
I have the following the layout file <?xml version=1.0 encoding=utf-8?> <RelativeLayout xmlns:android=http://schemas.android.com/apk/res/android xmlns:app=http://schemas.android.com/apk/res/com.company android:layout_width=fill_parent
I have the following layout: <?xml version=1.0 encoding=utf-8?> <RelativeLayout xmlns:android=http://schemas.android.com/apk/res/android android:layout_width=fill_parent android:layout_height=fill_parent> <GridView android:id=@+id/grid
I have the following layout in place <?xml version=1.0 encoding=utf-8?> <LinearLayout xmlns:android=http://schemas.android.com/apk/res/android android:orientation=vertical android:layout_width=fill_parent
I have the following layout in my xml file: <RelativeLayout android:layout_width=fill_parent android:layout_height=fill_parent> <FrameLayout android:id=@+id/logoLayout
I have following XML schema: <?xml version=1.0 encoding=UTF-8 standalone=no?> <xs:schema xmlns:xs=http://www.w3.org/2001/XMLSchema> <xs:element name=content type=contentType/>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.