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
34
votes
8 answers

marginTop does not work with ConstraintLayout and wrap_content

In my Fragment I have a ConstraintLayout with layout_height="wrap_content" and I would like to have a margin between my two buttons at the bottom of the view. When I add this margin as layout_marginBottom to the upper button (button_welcome_signup)…
22
votes
9 answers

How to set recycler height to highest item in recyclerView?

I need to make sure that horizontal recyclerView height is the same as the height of the biggest item. Items can have a different height (Item = always the same image + title + subtitle, title and subtitle could have infinite length). When I set…
17
votes
1 answer

GridLayoutManager - column width wrap its own largest child

I got a RecyclerView inside an HorizontalScrollView and I want it to use a GridLayoutManager. This is ok but one thing still bother me, the width of every columns are the same (based on the largest cell width I suppose?). Isn't it possible to wrap…
15
votes
2 answers

RecyclerView in SwipeRefreshLayout not "wrap_content"

I have a RecyclerView as the only child of SwipeRefreshLayout, I want the RecyclerView wrap_content. When I set both of them "wrap_content", it doesn't work. The RecyclerView with fewer items also match_parent. When i delete SwipeRefreshLayout, the…
8
votes
2 answers

Wrap Content in Jetpack Compose

How to make the parent layout - Box wrap its content in Jetpack compose? The current implementation below fills the entire screen, I only want the Box to wrap around its child - Switch. How do I define wrap content for the Box? @Composable fun…
Bullionist
  • 2,070
  • 3
  • 25
  • 42
8
votes
2 answers

Balanced Multiline TextView

I am starting with this: Which renders like this: | Here is what it looks | | …
mpkuth
  • 6,994
  • 2
  • 27
  • 44
7
votes
2 answers

How to prevent words from breaking in textview when using wrap_content?

I am in the process of trying to convert a desktop app to Android - and am struggling with some very basic stuff. When I specify a layout including a textview that holds a sizable amount of text wrap_content seems to arbitrarily break in the middle…
Rudi Diezmann
  • 71
  • 1
  • 2
7
votes
7 answers

ExpandableListView expandable list not expanding when its height is wrap_content, and something is below it

Here is my layout code. When i click on the expandable list view it does not expand. However, if I increase the height of list it expands. Is there a way to increase the height of list dynamically through code? Can i make it to expand in the middle…
5
votes
2 answers

Android some EditText fields don't respond to long-press (API 30+ with layout_width 0dp)

I'm wondering if anyone else has experienced this strange bug. My layout is complicated but essentially it's rows of view holders with EditText fields. It worked flawlessly until I updated my target SDK to API 30. After targetting API 30, some of my…
5
votes
1 answer

Item of RecyclerView inside a ConstraintLayout does not occupy the full width of its parent

I'm having a problem using a RecyclerView within a ConstraintLayout, and wanted to confirm that I'm not doing anything wrong before declaring it as a bug. Basically I've defined a RecyclerView inside a…
5
votes
1 answer

ViewGroup match_parent inside wrap_content

There is one LinearLayout with wrap_content layout parameters. I have several views inside it with the match_parent parameter. Let's take a look. Case 1:
5
votes
2 answers

RecyclerView height wrap_content calculation is incorrect

I want my RecyclerView to wrap_content. I don't want any scrolling inside RecyclerView, it should adjust to the height of inner children. I wan't my parent ScrollView to scroll the content of my activity.
Andrei
  • 42,814
  • 35
  • 154
  • 218
5
votes
2 answers

Relativelayout not wrapping its content

I want my inner RelativeLayout to wrap it's content and stay below the View element. Why isn't it behaving like the pic below? My layout.xml
4
votes
1 answer

Autosize a multiline textview in a ConstraintLayout

I'm trying to get a TextView which could be multiple lines tall and with the minimal width needed large. I tried a wrap_content width, but the TextView stays on a single line and overlaps parent if the text is too long. Then, I put the width to 0dp,…
4
votes
2 answers

How to wrap text using simple_list_item_multiple_choice?

I'm using a SimpleCursorAdapter to display a single CheckedTextView. I know this is done best using simple_list_item_multiple_choice and android.R.id.text1. adapter = new SimpleCursorAdapter(getApplicationContext(), …
kkudi
  • 1,625
  • 4
  • 25
  • 47
1
2 3 4 5 6 7