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

how to use correct dragging of a view on android

it seems that there are a lot of solutions of how to use dragging of views on android . however, they are either too slow or buggy. a known solution is to have a framelayout , and the view simply changes its layoutParams as it moves using the…
android developer
  • 114,585
  • 152
  • 739
  • 1,270
6
votes
2 answers

setLayoutParams() method doesn't work

I am making a code that changes its size according to the screen size its application provides. It gets the entire width and height(or its appropriate view's w and h) by onSizeChanged() and onDraw() methods of View. It worked well in another code…
June
  • 265
  • 1
  • 8
  • 21
6
votes
4 answers

custom Toast at screen top

Please read the question before answering with your standard routine to print a Toast :) I'd like to display a Custom Toast at the top left corner of the screen. I use this code to create the Toast: Toast mFixedToast = new…
rupps
  • 9,712
  • 4
  • 55
  • 95
6
votes
0 answers

Overlay a Full screen Transparent layer in Android 4.4(KitKat)

I want to overlay a transparent view on the entire screen including the bottom most Navigation Bar in Android 4.4. I am able to do so in Android 4.3 by defining the window Manager LayoutParams as TYPE_SYSTEM_OVERLAY, but when I use the same…
6
votes
2 answers

what to import to resolve "LayoutParams cannot be resolved to a variable"?

I am getting error LayoutParams cannot be resolved to a variable on a line of code which is as follows tv.setLayoutParams(new GridView.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 0.1f)); When i press ctrl+shift+o to import…
Sunil Kumar
  • 6,112
  • 6
  • 36
  • 40
6
votes
5 answers

how to set padding or margin to linear layout?

I have a linear layout
Alan Lai
  • 1,094
  • 7
  • 18
  • 41
5
votes
2 answers

EditText in dialog android

i have made a edittext in a dialog but i cant get to change the height. AlertDialog.Builder editalert = new AlertDialog.Builder(this); editalert.setTitle("messagetitle"); editalert.setMessage("here is the message"); final EditText input = new…
Hello
  • 119
  • 2
  • 11
5
votes
1 answer

Reset LayoutParams to what is defined in XML

I can't find a method that does this, but is there a way to reset the LayoutParams on an item? On rotation of the device, I change the layout params. When I turn back to portrait, I want to change them back to the XML values. Do I just have to…
Ronnie
  • 11,138
  • 21
  • 78
  • 140
5
votes
2 answers

"match_parent" height is not working for RelativeLayout inside NestedScrollView

I am using CoordinatorLayout as my root View in activity.xml. In that xml , I am using NestedScrollView with appbar_scrolling_view_behavior enabled. But the content inside the NestedScrollView is wrapping the height instead of Matching the…
Sasank Sunkavalli
  • 3,864
  • 5
  • 31
  • 55
5
votes
2 answers

Android: calling setPadding() on a view doesn't work when I also set the layoutParams on the view

If I call setPadding() on a view, I can successfully set the padding, however, if I first set the layoutParams and then the padding, or set the padding and then set the layoutParams, the padding is not applied. Demonstration: //This doesn't…
Micah Simmons
  • 2,078
  • 2
  • 20
  • 38
5
votes
4 answers

How to get height in pixels of LinearLayout with layout_weight

this is my first post. I am learning to code in java for android apps. I am using a LinearLayout "variable named: ll" with a predefined layout_weight (which I want to change whenever I want in the future) and height and width set to MATCH_PARENT. I…
Usman
  • 2,331
  • 2
  • 21
  • 29
5
votes
1 answer

Android navigation bar overlay

For my application I have to draw a bitmap on top of the Navigation bar on the bottom of the android screen. I am curious to know if the WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY can be used to overlay the navigation bar?
sash
  • 1,124
  • 2
  • 15
  • 32
5
votes
2 answers

ImageView getLayoutParams width unit

If I want to set the width/height of an ImageView programmatically in Java, like this: image_view.getLayoutParams().width = 200; What's the unit of those "200"? Is it px/dp? Does it look "the same" on every device? (That means: Is it extremely big…
Tobias Baumeister
  • 2,107
  • 3
  • 21
  • 36
5
votes
2 answers

Set LayoutParams of ListView when using DrawerLayout with Fragments

I want to change width and height of my Listview which is located in my DrawerLayout: DrawerLayout mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); DrawerLayout.LayoutParams myParam = new DrawerLayout.LayoutParams(20,…
user2242982
  • 61
  • 1
  • 5
5
votes
2 answers

WindowManager.LayoutParams why is there a setTitle method?

So yesterday i was programming and suddenly i came across the setTitle method in the WindowManager.LayoutParams class, why would this class like this have a setTitle method? Where is is used for? The documentation does not say anything about the…
Rolf ツ
  • 8,611
  • 6
  • 47
  • 72
1 2
3
30 31