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

Android ScrollView height

I have a problem making a ScrollView wrap the content. I don't know why but the ScrollView's height is bigger then the content I have and I read about some way to fix this but they didn't work. (layout_weight, fill_parents, wrap_content,…
0
votes
2 answers

HorizontalScrollView and image wrapping

I've implemented a LinearLayout with a tall/narrow image on the left side (top to bottom) and a HorizontalScrollView on the right side for showing a long image. The problem is that I have not managed to handle the HorizontalScrollView properly. It…
0
votes
0 answers

Wrap content equivalent for BottomSheetDialogFragment plus JetPack Compose's Scaffold that is too tall

I have the following BottomSheetDialogFragment package com.example.testbottomsheetheight import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import…
ademar111190
  • 14,215
  • 14
  • 85
  • 114
0
votes
0 answers

AutoCompleteTextView combine open results below (by setting dropDownHeight?) and wrap content

I'm using autoCompleteTextViews and i need the results to open below the field and wrap the content. My solution was to set dropDownHeight to a certain value that would guarantee i have enough room below. On 2 Samsung devices a tried, this works…
0
votes
0 answers

How can I set wrap_content layout using this code?

FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(400, 400); params.gravity = Gravity.TOP|Gravity.RIGHT; linearLayout.setLayoutParams(params); I am using this code but I want that I am using this code but I want that 400, replace with…
0
votes
1 answer

Why my custom view android takes all the space of my screen?

Let's take simple CustomView as an example public class MyView extends View { public MyView(Context context) { super(context); super.setBackgroundColor(Color.RED); } public MyView(Context context, @Nullable AttributeSet…
0
votes
1 answer

MeasureSpecs passed to onMeasure indicate the full parent size instead of the remaining available space

I'm observing an issue where the onMeasure method of my custom view is receiving a MeasureSpec that corresponds to the full parent view's size, instead of the remaining available space. This happens when the view's layout_width/height attributes are…
0
votes
1 answer

Reduce ListView height when there are fewer items

I have ListView to be used in the app widget. The list view has a fixed height of some 140 dp to accommodate 3 items, now when there is only one item to show, there is space left below the item. I want to be able to set the list view like this - set…
0
votes
1 answer
0
votes
2 answers

Android text view wrap to max of 2 lines

I'm trying to get a textview to occupy up to 2 lines (would only be 1 line if there is only 1 word / no spaces), but be as narrow as possible. For example: Short Medium Text Some longer text here Some very long text that might get very wide but will…
Charlie Walker
  • 129
  • 1
  • 2
  • 9
0
votes
1 answer

ViewPager problems

I set ViewPager's height wrap_content but it doesn't work. I tried answers in other similar questions but they didn't solve my problem. my activity_main code is this:
0
votes
4 answers

How to make a wrap_content text view wrap its content only enough to still make other views visible in LinearLayout android?

I have a horizontal LinearLayout with 3 text views with width set to wrap_content. I want them all to be wrap content, but there is a potential that one of them becomes too long. This results in the other two text views become out of bound. How can…
0
votes
1 answer

Constraint Layout is taking full width when a child is wrap_content in height

I want the test view to take only as much height as occupied by the rest of the card. (See images at the end of code snippet) But it is pushing the height of the view to the entire screen. It works as we want only after supplying 0 height, which…
0
votes
2 answers

Android TextView does not hug text tightly with multiple lines, sticks to maxWidth instead

I am creating a chat bubble and I noticed that when you have a TextView with text that spans multiple lines the width of the box locks to the (in this case) maxWidth. This may cause a gap on the right side:
Janneman
  • 1,093
  • 15
  • 23
0
votes
2 answers

layout does not have the right size

I'm creating a layout_banner.xml that is referenced by multiple other layouts, and has a height of 80dp. layout_banner.xml: