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;
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.
add a comment |
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.
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
add a comment |
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.
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.
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
add a comment |
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
add a comment |
1 Answer
1
active
oldest
votes
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;
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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;
add a comment |
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;
add a comment |
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;
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;
edited Mar 22 at 18:53
Onik
11.8k104264
11.8k104264
answered Mar 22 at 18:10
chipschips
888
888
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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