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
4
votes
1 answer

WindowManager.LayoutParams combination that can pass events to layers under TYPE_SYSTEM_ALERT or smilar

Can someone please help me to get WindowManager.LayoutParams combination that can pass events to layers under TYPE_SYSTEM_ALERT or similar overlay type (that sits top of every other window). Problem: My problem is when the window type…
SAN
  • 959
  • 4
  • 11
  • 17
4
votes
2 answers

Change view height in onTouch ACTION_MOVE

I would like to change view height when user move finger down on screen. new OnTouchListener() { float lastY = Float.MIN_VALUE; @Override public boolean onTouch(View v, MotionEvent event) { if…
Nik
  • 7,114
  • 8
  • 51
  • 75
4
votes
2 answers

How to expand view smoothly in Android?

I met an issue when I expanded a 320*50 view to full-screen. If I expand it directly, it works but the action is very abrupt and I think is not a good user experience. So I hide the view first, then expand it, and after two second, show the view…
wayne_bai
  • 1,218
  • 4
  • 14
  • 23
4
votes
1 answer

Dynamically change width of spinner in Android

I tried to dynamically change the width of a spinner with the code below, but I get an error message. What is the correct way to do this? Spinner s1 = (Spinner) findViewById(R.id.s1_10); s1.setLayoutParams(new LayoutParams(400,…
Rynardt
  • 5,547
  • 7
  • 31
  • 43
3
votes
2 answers

Android - add subview with layout params at specific index (in code)

I may be missing something, but I can't find a way to add a subview to a view at a specified index with specific layout params. There's addView(View v, LayoutParams lp) and there's addView(View v, int index) - but I can't find a way to specify…
Aleks G
  • 56,435
  • 29
  • 168
  • 265
3
votes
0 answers

Android : How to set Sliding Drawer topOffset/bottomOffset at runtime?

I came across this topOffset attribute of a Sliding Drawer. It seems pretty useful, but I would like to set it at runtime. Is this possible? I looked through the developer docs, couldn't find much.
Arnab Chakraborty
  • 7,442
  • 9
  • 46
  • 69
3
votes
4 answers

Blank screen when restoring screenBrightness Android

**Please note, Im just trying to turn off the display. If you have better method of doing this please suggest it :) I am using params.screenBrightness = 0; getWindow().setAttributes(params); and params.flags |=…
thegreyspot
  • 4,079
  • 5
  • 28
  • 34
3
votes
1 answer

Problem setting the layout_gravity on a button using LayoutParams

I am adding a button dynamically to a ListActivity. As follows: setContentView(R.layout.listview_singlegrey); LayoutInflater inflater = (LayoutInflater)this.getSystemService (Context.LAYOUT_INFLATER_SERVICE); LinearLayout linear = (LinearLayout)…
Dayerman
  • 3,973
  • 6
  • 38
  • 54
3
votes
1 answer

Android ConstraintLayout ConstraintLayout.LayoutParams.WRAP_CONTENT isn't working

I try to add a ConstraintLayout programmatically. It's working but WRAP_CONTENT isn't working. The Layout is always MATCH_PARENT. The Android Developer page doesn't list WRAP_CONTENT for ConstraintLayout.LayoutParams My Code: RelativeLayout rl_main…
3
votes
1 answer

Why am I getting class cast exception when I reference AppBarLayout and try to get it's LayoutParams using AppBarLayout.LayoutParams?

I am trying to get the Layout Params of AppBarLayout but I am getting this error. java.lang.ClassCastException: android.support.design.widget.CoordinatorLayout$LayoutParams cannot be cast to…
3
votes
3 answers

setLayoutParams() animation duration doesnt work

I have LayoutParams transition with addRule(). My view changes position but duration is instant. I work on API 15 so I cant use beginDelayedTransition(). Animation a = new Animation() { @Override protected void applyTransformation(float…
3
votes
2 answers

Android M ClassCastException: FrameLayout$LayoutParams cannot be cast to WindowManager$LayoutParams

This piece of code works seems to work in android api 16 - 22 but does not work in api 23. I'm simply trying to display a popupwindow with options in it and dim the background below the popupwindow: WindowPopUp windowPopUp = …
Simon
  • 19,658
  • 27
  • 149
  • 217
3
votes
3 answers

Dialog with blurry background at certain position

I am trying to have a blurry background behind an AlertDialog. The process goes like the following: take a screenshot of the activity and blur it and save it to a bitmap. Then converting this bitmap to a drawable. Then I set the drawable background…
Ziad Halabi
  • 964
  • 11
  • 31
3
votes
1 answer

What is the order and meaning of WindowManager.LayoutParams constructor parameters?

I cannot find a description of the order and meaning of LayoutParams' constructor parameters. This is all I can find on developer.android.com: WindowManager.LayoutParams() WindowManager.LayoutParams(int _type) WindowManager.LayoutParams(int…
3
votes
2 answers

LinearLayout.getWidth() not reflecting new width from setLayoutParams

tl/dr I am trying to change some layouts sizes in code, and I can change some of them, but the other ones that needed to update based on the changes won't update together. Instead, they retain the previous width that the changed ones had. So,…
GuiFGDeo
  • 706
  • 1
  • 8
  • 29