Questions tagged [fill-parent]

FILL_PARENT (renamed MATCH_PARENT starting Android API Level 8), is a constant describing that a view would like to be as big as its parent (minus any padding).

FILL_PARENT (renamed MATCH_PARENT starting Android API Level 8), is a constant describing that a view would like to be as big as its parent (minus padding). It can be used for both width and height. It is the opposite of WRAP_CONTENT, which indicates that the view wants to be just big enough to enclose its content (plus padding).

Both constants are part of the ViewGroup.LayoutParams class, from which all other LayoutParams derive, and aid in ensuring that Android applications can display properly across a variety of device screen sizes and densities. The equivalents in XML share the same names, but all lowercase.

The sample below describes a LinearLayout that vertically stacks a TextView and Button. The LinearLayout requests to be sized as big as its parent by means of android:layout_width="match_parent" and android:layout_height="match_parent". The two child views, however, are requested to limit their width and height to their contents using the wrap_content values.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:orientation="vertical" >
    <TextView android:id="@+id/text"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:text="Hello, I am a TextView" />
    <Button android:id="@+id/button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Hello, I am a Button" />
</LinearLayout>
73 questions
36
votes
2 answers

Is there a way to fill parent minus a fixed number in Android RelativeLayout?

I have an ImageButton that I want to fill its parent RelativeLayout container for its width but minus a few dp so it has some left and right padding. I tried fill_parent-10dp but that causes an error and doesn't render.
29
votes
9 answers

How can I use layout_width using resource file?

There are a activity what I want to fill the screen in a phone and pop up(dialog) for a tablet. I thought I make a layout file like this,
Shakra
  • 291
  • 1
  • 3
  • 3
19
votes
6 answers

Scaling an image to max available width, keeping aspect ratio and avoiding ImageView extra space

I have this simple layout XML, and a green_square.png file which is 30X30 pixels
Shlomi Schwartz
  • 8,693
  • 29
  • 109
  • 186
16
votes
4 answers

Set AdMob banner to match parent width by XML

I'm trying to set AdMob banner ad to match it's parent width. I tried as sample:
David
  • 37,109
  • 32
  • 120
  • 141
14
votes
1 answer

Android 3 - Adding a Fragment to a LinearLayout: fill_parent does not work

I am trying to add a fragment programmatically to a LinearLayout, but the fragment does not stretch its content across the whole layouts height. It acts like wrap_content instead of fill_parent. On the other side the fill_parent works on the…
14
votes
8 answers

Child of RelativeLayout is not filling the height of the RelativeLayout

I have a ListView which gets populated with RelativeLayouts. The content of these RelativeLayouts can change and thus change their height respectively. On each RelativeLayout, I have a little vertical bar on the left side of the layout that matches…
vivatus
  • 2,253
  • 4
  • 18
  • 23
10
votes
7 answers

Why EditText is not expanding to fill_parent

I have written an XML code, where I want the EditText to be expanded to fit the parent width. After spending so much time, I can not find a way to expand the EditText. Here is my XML:
user1462473
  • 115
  • 1
  • 5
8
votes
2 answers

Android fill_parent to match_parent

What was the reason behind introducing match_parent and deprecating fill_parent since both mean the same thing. won't this change be a hindrance to backward compatibility?
1O1
  • 713
  • 10
  • 15
7
votes
5 answers

android imageview wrap_content

Hello everyone and thanks for your help. I have a project in Android Studio. I am using an ImageView inside vertical LinearLayout. Here are my parameters;
yucel
  • 365
  • 4
  • 11
6
votes
1 answer

How to stretch ListView items width to fill parent container?

How to stretch listview items width to fill parent container? The default behaviour seems to be squishing everything as narrow as possible.
6
votes
1 answer

Programmatically using MATCH_PARENT for a RelativeLayout inside a FrameLayout

I'm subclassing HorizontalScrollView (which is a FrameLayout) and adding a RelativeLayout to it programmatically. The FrameLayout correctly fills the parent view, but RelativeLayout inside doesn't show…
5
votes
2 answers
5
votes
5 answers

Android - EditText multiline forced to fill height

I need a EditText that fills in height my window. I'm using this:
Lorenzo Sciuto
  • 1,655
  • 3
  • 27
  • 57
4
votes
2 answers

android: layout: How to make my dialog box fill the screen with the XML

I'm trying to get a Dialog box to open covering most the screen (by that I mean it still has its nice rounded effect but cover the content behind) I've been trying with fill parent but it keeps behaving like a wrap content
Jason Rogers
  • 19,194
  • 27
  • 79
  • 112
3
votes
2 answers

ImageView in a Custom Dialog - fill_parent does not work and my dialog is small

I have a simple request: I have to put some pictures (some small resolution, some big resolution) in a dialog and display them fullscreen. I tried this: Dialog dialog = new Dialog(getActivity()); dialog.setContentView(R.layout.custom_dialog); int…
Waza_Be
  • 39,407
  • 49
  • 186
  • 260
1
2 3 4 5