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
4
votes
2 answers

How to scale the view to fit the content size in Android animation?

I am using CardView as a item of Recycler Adapter. At first, all items will not show the whole content, (I cut it and put the '... ...' instead) but after click it, the clicked item will scale its height to fit the content height. ( Here I set the…
4
votes
1 answer

How I can create a RecyclerView with fixed size image that wrap contents and image is crop centered

this is my desired goal: I want to show my Grid Items in 3 rows with recyclerview. I also have fixed image size in dp 120dpx120dp. but I want to my grid Items fill all the vertical space so that there is no blank space in recyclerView and. so I…
Mahdi
  • 6,139
  • 9
  • 57
  • 109
4
votes
2 answers

RecyclerView with wrap content items

I need to implement next UI element: Unknown size list of strings (That came from a server call) Any item should be wrap content. If an item is not fits to row, he will be in the next row. All list/grid is centered I thought of using…
3
votes
1 answer

Unable to wrap labels of buttons inside Material Button Toggle Group

I have three buttons inside a MaterialButtonToggleGroup. The issue is that all the labels are being cut off and not wrapped.
Shizuku
  • 147
  • 1
  • 9
3
votes
0 answers

Issue with wrap_content in ExoPlayerView. ExoPlayerView height remain 0 at run-time if it set to wrap_content

I want my player to adapt the height of video so I'm using Exo player view with wrap_content height. but it's not working.
Vishva Vijay
  • 340
  • 3
  • 11
3
votes
1 answer

How to make "wrap_content" work after altering content in Android Motion Layout?

The 'wrap_content' not work properly in MotionLayout when setting a new value. I created a sample with a TextView above RecyclerView. The TextView was set to android:layout_height="wrap_content" and android:text='Hello World! at first. Then…
3
votes
0 answers

Setting GridView width wrap_content

I am trying to use a gridView for a game with different board sizes. I sets the number of columns programmatically for the GridView, each column got an fixed size button inside it.The GridView width is set to "wrap_content" in the xml. However - The…
Nakash.i
  • 371
  • 1
  • 3
  • 13
3
votes
2 answers

Android ConstraintLayout wrap_content does not show all the contents

I need to show all data in TextView, it must occupy all the available space horizontally and contain all the data vertically(it is necessary for different screen sizes or device orientation). But it does not take the necessary vertical area: Is it…
3
votes
3 answers
2
votes
2 answers

TextView with wrap_content in overlay not extending to full content width

In my application I have a overlay with a TextView, which has a dynamic text size and content and can be moved using touch. The goal is to make the overlay the same size as the text. Using WRAP_CONTENT for the overlay, does not extent the…
zuim
  • 1,039
  • 8
  • 10
2
votes
1 answer

Anomalous WRAP_CONTENT behaviour

It's supposed that WRAP_CONTENT does this: Special value for the height or width requested by a View. WRAP_CONTENT means that the view wants to be just large enough to fit its own internal content, taking its own padding into account. But the…
NullPointerException
  • 36,107
  • 79
  • 222
  • 382
2
votes
2 answers

How to remove top and bottom padding on a textView?

I have a textView which I want to remove every padding and extra space at the top and bottom of the text. This is my XML:
bcsta
  • 1,963
  • 3
  • 22
  • 61
2
votes
1 answer

Android | ScrollView | height wrap_content

How does Android think about ScrollViews? I come from webdev background, so that is my paradigm for implementing a scrolling element. Yet on Android, official tutorials and docs say, I should use height="wrap_content" for the ScrollView. But…
2
votes
2 answers

buttons on toolbar too wide (android)

I have two buttons on the toolbar which are not obeying the "wrap_content" layout_width directive. I have added green and red background colors to make their true widths apparent in the screenshot. I have padding set to 0dp and also no margins. I…
Casey Perkins
  • 1,853
  • 2
  • 23
  • 41