When is the Activity root view inflated?Why does calling getWidth() on a View in onResume() return 0?How do save an Android Activity state using save instance state?Activity restart on rotation AndroidStop EditText from gaining focus at Activity startupHow do I pass data between Activities in Android application?Activity has leaked window that was originally addedGet root view from current activityDilemma: when to use Fragments vs Activities:LayoutInflater view not stretching to match_parentSet project wide default for layout_width and layout_heightHow to put the new view on top of the root view using LayoutInflater

"The cow" OR "a cow" OR "cows" in this context

A ​Note ​on ​N!

Nails holding drywall

How important is it that $TERM is correct?

What *exactly* is electrical current, voltage, and resistance?

How much of a wave function must reside inside event horizon for it to be consumed by the black hole?

Was Dennis Ritchie being too modest in this quote about C and Pascal?

What makes accurate emulation of old systems a difficult task?

Is there metaphorical meaning of "aus der Haft entlassen"?

UK Visa refusal and ban for 10 years ( false Documents) . Can I apply for Australia

Why must Chinese maps be obfuscated?

Apply a different color ramp to subset of categorized symbols in QGIS?

How can I wire a 9-position switch so that each position turns on one more LED than the one before?

Should the Product Owner dictate what info the UI needs to display?

Magical attacks and overcoming damage resistance

What is the term for a person whose job is to place products on shelves in stores?

How long after the last departure shall the airport stay open for an emergency return?

NPN: Not fully sinking to GND

What to do with someone that cheated their way through university and a PhD program?

Double-nominative constructions and “von”

Prove that the countable union of countable sets is also countable

What is the most expensive material in the world that could be used to create Pun-Pun's lute?

How do I check if a string is entirely made of the same substring?

I preordered a game on my Xbox while on the home screen of my friend's account. Which of us owns the game?



When is the Activity root view inflated?


Why does calling getWidth() on a View in onResume() return 0?How do save an Android Activity state using save instance state?Activity restart on rotation AndroidStop EditText from gaining focus at Activity startupHow do I pass data between Activities in Android application?Activity has leaked window that was originally addedGet root view from current activityDilemma: when to use Fragments vs Activities:LayoutInflater view not stretching to match_parentSet project wide default for layout_width and layout_heightHow to put the new view on top of the root view using LayoutInflater






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








4















The docs for the setContentView() method in the Activity class state that the view is added to the activity window AND inflated. However, the width and height of the root view are both zero after setContentView() is called.



Example below:



Activity class



public class MainActivity extends AppCompatActivity 

private static final String TAG = "myTag";

@Override
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

View root = ((ViewGroup) this.findViewById(android.R.id.content)).getChildAt(0);
// Here I expect the root view to have been inflated and have a width and height
Log.i(TAG, "Root view width:" + root.getWidth() + " height:" + root.getHeight());




Layout XML



<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
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"
tools:context=".MainActivity">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
android:layout_gravity="center_horizontal|center_vertical" />

</FrameLayout>


My problem is I need to create a bitmap image of the root view upon the launch of the activity and I'm not sure when I should do this that guarantees the root view has been inflated.










share|improve this question



















  • 2





    Why does calling getWidth() on a View in onResume() return 0?

    – Onik
    Mar 22 at 17:34












  • Possible duplicate of Why does calling getWidth() on a View in onResume() return 0?

    – Taslim Oseni
    Mar 22 at 18:47

















4















The docs for the setContentView() method in the Activity class state that the view is added to the activity window AND inflated. However, the width and height of the root view are both zero after setContentView() is called.



Example below:



Activity class



public class MainActivity extends AppCompatActivity 

private static final String TAG = "myTag";

@Override
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

View root = ((ViewGroup) this.findViewById(android.R.id.content)).getChildAt(0);
// Here I expect the root view to have been inflated and have a width and height
Log.i(TAG, "Root view width:" + root.getWidth() + " height:" + root.getHeight());




Layout XML



<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
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"
tools:context=".MainActivity">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
android:layout_gravity="center_horizontal|center_vertical" />

</FrameLayout>


My problem is I need to create a bitmap image of the root view upon the launch of the activity and I'm not sure when I should do this that guarantees the root view has been inflated.










share|improve this question



















  • 2





    Why does calling getWidth() on a View in onResume() return 0?

    – Onik
    Mar 22 at 17:34












  • Possible duplicate of Why does calling getWidth() on a View in onResume() return 0?

    – Taslim Oseni
    Mar 22 at 18:47













4












4








4








The docs for the setContentView() method in the Activity class state that the view is added to the activity window AND inflated. However, the width and height of the root view are both zero after setContentView() is called.



Example below:



Activity class



public class MainActivity extends AppCompatActivity 

private static final String TAG = "myTag";

@Override
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

View root = ((ViewGroup) this.findViewById(android.R.id.content)).getChildAt(0);
// Here I expect the root view to have been inflated and have a width and height
Log.i(TAG, "Root view width:" + root.getWidth() + " height:" + root.getHeight());




Layout XML



<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
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"
tools:context=".MainActivity">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
android:layout_gravity="center_horizontal|center_vertical" />

</FrameLayout>


My problem is I need to create a bitmap image of the root view upon the launch of the activity and I'm not sure when I should do this that guarantees the root view has been inflated.










share|improve this question
















The docs for the setContentView() method in the Activity class state that the view is added to the activity window AND inflated. However, the width and height of the root view are both zero after setContentView() is called.



Example below:



Activity class



public class MainActivity extends AppCompatActivity 

private static final String TAG = "myTag";

@Override
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

View root = ((ViewGroup) this.findViewById(android.R.id.content)).getChildAt(0);
// Here I expect the root view to have been inflated and have a width and height
Log.i(TAG, "Root view width:" + root.getWidth() + " height:" + root.getHeight());




Layout XML



<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
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"
tools:context=".MainActivity">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
android:layout_gravity="center_horizontal|center_vertical" />

</FrameLayout>


My problem is I need to create a bitmap image of the root view upon the launch of the activity and I'm not sure when I should do this that guarantees the root view has been inflated.







android android-view






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 22 at 18:53









Onik

11.8k104264




11.8k104264










asked Mar 22 at 16:35









chipschips

888




888







  • 2





    Why does calling getWidth() on a View in onResume() return 0?

    – Onik
    Mar 22 at 17:34












  • Possible duplicate of Why does calling getWidth() on a View in onResume() return 0?

    – Taslim Oseni
    Mar 22 at 18:47












  • 2





    Why does calling getWidth() on a View in onResume() return 0?

    – Onik
    Mar 22 at 17:34












  • Possible duplicate of Why does calling getWidth() on a View in onResume() return 0?

    – Taslim Oseni
    Mar 22 at 18:47







2




2





Why does calling getWidth() on a View in onResume() return 0?

– Onik
Mar 22 at 17:34






Why does calling getWidth() on a View in onResume() return 0?

– Onik
Mar 22 at 17:34














Possible duplicate of Why does calling getWidth() on a View in onResume() return 0?

– Taslim Oseni
Mar 22 at 18:47





Possible duplicate of Why does calling getWidth() on a View in onResume() return 0?

– Taslim Oseni
Mar 22 at 18:47












1 Answer
1






active

oldest

votes


















3














As @Onik correctly commented, he has already answered my question here Why does calling getWidth() on a View in onResume() return 0?



I would add that you could also attach an addOnLayoutChangeListener to your view and remove it in onLayoutChange(). It's ugly, but seems to be the only way;






share|improve this answer

























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55304110%2fwhen-is-the-activity-root-view-inflated%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    3














    As @Onik correctly commented, he has already answered my question here Why does calling getWidth() on a View in onResume() return 0?



    I would add that you could also attach an addOnLayoutChangeListener to your view and remove it in onLayoutChange(). It's ugly, but seems to be the only way;






    share|improve this answer





























      3














      As @Onik correctly commented, he has already answered my question here Why does calling getWidth() on a View in onResume() return 0?



      I would add that you could also attach an addOnLayoutChangeListener to your view and remove it in onLayoutChange(). It's ugly, but seems to be the only way;






      share|improve this answer



























        3












        3








        3







        As @Onik correctly commented, he has already answered my question here Why does calling getWidth() on a View in onResume() return 0?



        I would add that you could also attach an addOnLayoutChangeListener to your view and remove it in onLayoutChange(). It's ugly, but seems to be the only way;






        share|improve this answer















        As @Onik correctly commented, he has already answered my question here Why does calling getWidth() on a View in onResume() return 0?



        I would add that you could also attach an addOnLayoutChangeListener to your view and remove it in onLayoutChange(). It's ugly, but seems to be the only way;







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Mar 22 at 18:53









        Onik

        11.8k104264




        11.8k104264










        answered Mar 22 at 18:10









        chipschips

        888




        888





























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55304110%2fwhen-is-the-activity-root-view-inflated%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

            용인 삼성생명 블루밍스 목차 통계 역대 감독 선수단 응원단 경기장 같이 보기 외부 링크 둘러보기 메뉴samsungblueminx.comeh선수 명단용인 삼성생명 블루밍스용인 삼성생명 블루밍스ehsamsungblueminx.comeheheheh

            155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해