Questions tagged [android-wrap-content]

In Android, "wrap content" will wrap the view's size so that it will be just big enough to enclose its content. Use this tag for issues related to this layout param (whether on XML Layout or programmatically)

There are 3 possible values when deciding the size of a view:

  • Wrap content (XML: wrap_content, code: WRAP_CONTENT)
  • Match parent (XML: match_parent, code: MATCH_PARENT)
  • Exact number

"Wrap content" will wrap the view's size so that it will be just big enough to enclose its content.

wrap content vs match parent

Demonstration on Suragch's answer for the difference between "wrap content" and "match parent"


See also:

105 questions
1
vote
2 answers

wrap_content doesn't wrap content

I am a beginner in Android Programming. I was creating an app and I want to underline a text. Please have a look into my code snippet…
1
vote
1 answer

Can't add custom view dynamically with WRAP_CONTENT as height and width

I am trying to add multiple custom views to a frame layout but it always takes the whole width and height of the frame layout. The custom view only contains a 50x50 image which I want to be able to move around the frame layout, but as the custom…
Chain Cross
  • 351
  • 1
  • 2
  • 12
1
vote
0 answers

AndroidX Horizontal RecyclerView wrap_content not working?

RecyclerView horizontal was worked in support library. after converting to androidx is not working when using the wrap_content. My layout looks like this
1
vote
1 answer

RelativeLayout matching parent although it shouldn't

I'm trying to create a message layout in a chat application. This message layout should contain: Message Textview in a rounded rectangle Message status check icon ImageView within that same rectangle Message send time TextView outside the rounded…
1
vote
1 answer

How to set ImageView align to parent bottom and scaleType

I'm trying to align an image to it's parents bottom. The basic idea is to fit the image to screen width, use wrap_content for height and then align all that to the parent's bottom. Unfortunately the result is a 1-2dp margin at the bottom I cannot…
1
vote
0 answers

TextView drawableStart wrap_content doesn't work well

I want to display a textview with a compound drawable which wraps the content - the shape and the text. Here is my code:
Vin Norman
  • 2,749
  • 1
  • 22
  • 33
1
vote
2 answers

The property wrap_content is not working

I have to make a TextView horizontal inside a LinearLayout and vertical inside a ConstraintLayout. The problem is that the property wrap_content of the TextView is not working. This is the xml file:
1
vote
2 answers

Android fitting image to only needed space

I have an image I want to display with text above it and a line below. I want the image to use the width of the space provided, then the height just enough to not waste space. The current XML setting is:
1
vote
0 answers
1
vote
2 answers

Relative Layout - Automatic wrapping

I have the following code snippet:
1
vote
0 answers

Nested RecyclerView wrap_content causes OutOfMemoryError

I have a NestedScrollView, it contains a RecyclerView wrap_content: LinearLayoutManager layoutManager = new…
Norutan
  • 1,480
  • 2
  • 14
  • 27
1
vote
3 answers

Is it possible set wrapContent attribute on view without parrent?

I have a simple button view, and set it as content view. Is it possible to resize this view programmaticly to "wrap_content"? Button button = new Button(getContext()); button.setText("Some text"); setContentView(button);
1
vote
0 answers

Android DialogFragment wrap_content doesnt work

PopupDialog extends DialogFragment this; @Nullable @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View view = inflater.inflate(R.layout.lyt_dialog_popup,…
kibar
  • 822
  • 3
  • 17
  • 37
1
vote
1 answer

Why does wrap_content is filling height?

I am trying to have a RelativeLayout wrap it's content height and width. It seems to do fine on width, but the height does not wrap. It covers the entire screen. Anyone know why?
steventnorris
  • 5,656
  • 23
  • 93
  • 174
1
vote
0 answers

FrameLayout and TabHost - wrapping/scrolling

I have a problem with my layout. On large screens tab content is wrapped (between the end of the content and the buttons at the bottom you will see only the background). On the other hand on small screens scrollbar is visible. Is there a way to do…