Questions tagged [layoutparams]

The LayoutParams is a helper class that stores various layout information related to the Android view for which it is used.

The LayoutParams class is generally implemented as a nested class(in the ViewGroup that will use it) and it is present in all of the platform's default subclasses of ViewGroup. The class stores information like the widget size but can also store other details like the gravity of the view or the coordinates on the screen. Each of this value will be used by the parent to determine how to show that child View on the screen.

The LayoutParams is an important class and the user should take care and always use the appropriate LayoutParams for each View. The general rule of setting a LayoutParams for a View is to use the type of LayoutParams declared by its parent.

459 questions
5
votes
2 answers

Making a ListAdapter-recycleable Resizable View

I'm working on creating a custom view that will have an expanded and condensed state -- in the condensed state, it will just show a label and an icon, and in the expanded state, it will show a message below that. Here is a screenshot of how it works…
Kevin Coppock
  • 133,643
  • 45
  • 263
  • 274
5
votes
2 answers

android : set margin between buttons with LayoutParams

I want to automatically generate buttons vertically with a bottom margin of 20px between buttons. I try to set margin with a LayoutParams object, without success.
johann
  • 1,115
  • 8
  • 34
  • 60
4
votes
1 answer

Add a margin to LinearLayout in Android

I have some problems with setting margin! body_content = (LinearLayout) findViewById(R.id.body_content); int gSLength = 2; body_content.setPadding(10, 0, 10, 0); for (int i = 0; i < 1; i++){ FrameLayout fl = new FrameLayout(this); …
Kren_DEL
  • 105
  • 1
  • 6
4
votes
2 answers

Android FrameLayout and TextView - why does LayoutParams work where setGravity() does not?

I'm using a FrameLayout to display (on demand) some text on the screen. I want the text to be in a certain place, so I thought setGravity() would do the job... but no, it seems to have no effect whatsoever on where the text goes (and other objects…
MartyMacGyver
  • 9,483
  • 11
  • 47
  • 67
4
votes
2 answers

Getting all MotionEvents with WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH

My question refers directly to this question. The answer to that question shows how one can create a ViewGroup, embed it inside a WindowManager, and allow the WindowManager to catch MotionEvents through onTouchEvent(MotionEvent event).…
Brian
  • 7,955
  • 16
  • 66
  • 107
4
votes
1 answer

How to set layout params to edittext in dialog?

I'm trying to set some layout params to an edittext in a dialog but it seems to have no effect. Why? How can I reduce the width of my edittext? AlertDialog.Builder builder = new AlertDialog.Builder(context); builder = new…
jul
  • 36,404
  • 64
  • 191
  • 318
4
votes
1 answer

android setLayoutParams for webview generates ERROR

is it possible to set mWebView = (WebView) findViewById(R.id.webviewHelp); mWebView.setLayoutParams(new ViewGroup.LayoutParams(100, 200)); here mWebView.setLayoutParams(new Gallery.LayoutParams(70,85)); is also tested but not working…
Android
  • 8,995
  • 9
  • 67
  • 108
4
votes
2 answers

Why isn't setLayoutParams changing the size of my ImageView?

I have done this in the past and I am frustrated because this method is not working like I expect it to. I have an image that I want to resize to specific dimensions and I am using the code below: snellen.post(new Runnable() { @Override …
cjnash
  • 1,228
  • 3
  • 19
  • 37
4
votes
1 answer

RecyclerView getLayoutParams returns null (sometimes)

I have a RecyclerView, for which I have a custom Adapter, and I have set the LayoutManager to be a FlexboxLayoutManager. For every child, I want to set FlexGrow to be 1. In Google's example, demo-cat-gallery…
Luke Needham
  • 3,373
  • 1
  • 24
  • 41
4
votes
1 answer

Android: Check if view is aligned to parent bottom/top programmatically

How can I check if my view is aligned to it's parent bottom (or top). If the view is aligned to the parent bottom, I want to align it to the parent top, and vice versa. I am able to align the view as I want but I don't know how to check it first. My…
fractal5
  • 2,034
  • 4
  • 29
  • 50
4
votes
0 answers

getLayoutParams().width VS setMax/MinimumWidth() for ImageView

I do all my layout code via Java (no XML what-so-ever). However I found some peculiar behavior when setting an ImageViews height and width. Whenever I try to set it's dimensions with .setMinimumHeight and .setMaximumHeight (using the same value), I…
Aggressor
  • 13,323
  • 24
  • 103
  • 182
4
votes
2 answers

Android: How to make the SearchView take up the entire horizontal space in ActionBar?

In the following screenshot, the SearchView widget in the ActionBar does not take up the entire space available. I need it to take up all the horizontal space present in the ActionBar (so it spans the entire screen horizontally). What I…
Solace
  • 8,612
  • 22
  • 95
  • 183
4
votes
2 answers

setLayoutParams doesn't work second time

I have written the following code to first increase the size of ImageView and after 100ms decrease the size of the same ImageView. However this code increases the size of ImageView but it doesn't decrease it's size or the code after 100ms delay…
Umer Farooq
  • 7,356
  • 7
  • 42
  • 67
4
votes
2 answers

Android, How to get/set layout parameters?

In my application I have a conversation room. All of my messages should be aligned to right while the rest should be left aligned. Single row of my list is like this:
Hesam
  • 52,260
  • 74
  • 224
  • 365
4
votes
1 answer

setLayoutParams vs addView for adding a new view

What is the difference between using setLayoutParams and supplying the parameters to addView? I understand that addView only works when adding the view for the first time. I found two ways of apparently doing the same…
hultqvist
  • 17,451
  • 15
  • 64
  • 101