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 8409087
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T23:48:39+00:00 2026-06-09T23:48:39+00:00

I have layout which has a button. In the graphical layout editor, the button

  • 0

I have layout which has a button. In the graphical layout editor, the button fills width and has wrap_content height which gives the text some padding (as a usual button does). However, when launching an activity with this layout, the button sometimes decides to closely wrap the text, making a very small thin button.

When i say sometimes, I do mean sometimes, performing exactly the same action in my app may or may not generate this result.

I think the issue is related to the activity this is launched from, which is one with a camera preview. Like others have done, this app uses a landscape layout with vertical components on it to make it looks right while holding the phone in portrait (its a mess, i know, but we want to support api7).

So, my problematic activity/layout is launched from this cameraActivity, and in the process, the orientation changes. I believe this to be the source of the issue.

There is the button layout:

<Button android:id="@+id/ContinueBtn"
    android:text="@string/btn_continue"
    style="@style/main_button"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:typeface="normal"
    android:onClick="onButtonAction"
    android:background="@drawable/button_animated" >
</Button>

And for reference, the activity sets itself to portrait BEFORE setting the layout which includes this button.

So to summarise, I am getting a thin, wide button, some of the time. The other times I am getting a normal, healthy, non starved, button. I believe this is due to screen orientation changing – as the orientation changes it seems the layout engine sometimes manages to miss the default padding a button has. My question is firstly, what is causing this? Am I right? Secondly: how can I prevent this?


I should also add, that I think this has something to do with my custom background for the image – I haven’t been able to make it happen with a default button.

Also, here are some images of the problem:
Hungry Button
Who ate all the pies button
EDIT2: so, some solutions have been suggested in the comments below. but can anyone explain why this effect is so inconsistent? is there some kind of race condition?

  • 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-09T23:48:40+00:00Added an answer on June 9, 2026 at 11:48 pm

    Thanks to Espiandev and Wasaig for suggesting some solutions to this problem. My issue turned out to be with ‘constantSzie=”true”‘ in my selector for the button (which admittedly, I didn’t provide in the original question.

    Turning this off will fix the issue (as will either of the two other solutions mentioned in comments).

    As it stands however, constantSize is NOT working (as far as my understanding goes). I believe there is a bug somewhere in the code where it obtains the constant size (I’ve looked through the source code here, and cannot spot anything immediately wrong: http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/4.0.3_r1/android/graphics/drawable/DrawableContainer.java#DrawableContainer.DrawableContainerState.computeConstantSize%28%29 ). I suspect the intrinsicSize is being returned as ‘-1’.

    I have submitted an android bug report here which includes a sample project that generated the bug:
    http://code.google.com/p/android/issues/detail?id=36432

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

Sidebar

Related Questions

I have a layout which looks like this: <LinearLayout> <ImageView> android:width=wrap_content android:height:wrap_content ... </ImageView>
I have in my layout a button, which is has to change image when
I have a XML layout which has two edit text fields, one for title
I have an alternate homepage template, homepage.pt, which has a different layout. When I
Say I have a main screen Layout which has to move up, to reveal
I have a Relative Layout. Which has 2 buttons, side by side and it
I am trying to build a layout dynamically which display some text and image
I have some layout/button and onClick I get TimePickerDialog with current time (previously defined
I have an Activity which has an 'OK' button. And I have an 'Edit'
I've a layout now, which has a add location button. The current layout is

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.