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.

453 questions
232
votes
16 answers

Auto-fit TextView for Android

Background Many times we need to auto-fit the font of the TextView to the boundaries given to it. The problem Sadly, even though there are many threads and posts (and suggested solutions) talking about this problem (example here, here and here),…
android developer
  • 106,412
  • 122
  • 641
  • 1,128
70
votes
3 answers

How do I programmatically remove an existing rule that was defined in XML?

I have a linear layout that is contained inside a relative layout. It is set in the XML file to be to the right of another linear layout (this works fine). In some cases I want to change the relative position of the layout during the onCreate of…
39
votes
3 answers

Layout params of loaded view are ignored

I'm trying to write my own custom View and I have problem with LayoutParams. The idea is to extend ViewGroup (LinearLayout) public class MyView extends LinearLayout{ public MyView(Context context, AttributeSet attrs) { super(context,…
Max Komarychev
  • 2,676
  • 1
  • 18
  • 30
29
votes
1 answer

After changing a property on a LayoutParams object, do I need to call setLayoutParams again?

I have a View (containing an ad) that I need to scale to fit the screen width at a certain point in time (after the ad is loaded). So I have a method setHeight(myView) that calculates the correct height for the given screen width and changes the…
david.mihola
  • 10,142
  • 5
  • 41
  • 62
29
votes
3 answers

android: LayoutParams for TextView makes the view disappear, programmatically

I've hit this from various different angles. Basically the gist is this: I've layed out a template in XML for an interface which NEEDS to be run programmatically, so it's going to be populated dynamically during the run. The problem here, is that…
Octoth0rpe
  • 2,187
  • 4
  • 17
  • 21
24
votes
1 answer

How to set layout_span through code

Does anyone know how to set/change the android:layout_span="" of an EditText in Android at runtime. I already have the EditText defined in my XML file.
L4N0
  • 267
  • 1
  • 4
  • 7
23
votes
3 answers

What unit of measure does LayoutParams use?

pI am working with a linear layout and want to set the maximum height of the view. Under "normal" circumstances, I want the view to use "wrap_content." However, occasionally the circumstances may push the layout to an undesirable size. When this…
Roy Hinkley
  • 8,420
  • 18
  • 68
  • 112
21
votes
5 answers

How to find the Text Area(Height/Width) of TextView programmatically in android

I have an EditText, a Button and a TextView. On clicking the button, textview shows the text written in edittext. Is it possible to find the size of textview occupied depending upon text. i.e. If It has three characters "abc", what is width now, if…
BST Kaal
  • 2,743
  • 5
  • 31
  • 51
18
votes
2 answers

How do you change the size of an ImageView?

I have setup my ImageView like the following:
atedja
  • 1,316
  • 2
  • 10
  • 13
17
votes
2 answers

Setting Layout parameters in android

Working with the XML file was easy as I could specify the parameters as But I am confused while specifying it through code. For each view I specify the parameters using…
Jerrin George
  • 317
  • 1
  • 2
  • 13
16
votes
5 answers

Animation in changing LayoutParams in LinearLayout

In my app there is a LinearLayout which has 0 Layout height. When I click the button this layout height should be LayoutParams.WRAP_CONTENT. This is the code I use in onclicklistner. LayoutParams lp = new LayoutParams(LayoutParams.FILL_PARENT,…
Chrishan
  • 4,034
  • 7
  • 44
  • 63
16
votes
3 answers

Setting margin programmatically to CardView

I have a CardView in my XML layout and I need to set margins to it programmatically (This is because I don't need margin at all times. Based on few conditions, I either set or remove the margin). Here's how I did it: CardView.LayoutParams…
15
votes
3 answers

android Exit from full screen mode

I am working in Android. I need to show my activity in Full screen mode, and i did this using following code. getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); Now…
Pushpendra Kuntal
  • 5,722
  • 17
  • 66
  • 119
14
votes
3 answers

Android view's getTop(), getLeft(), getX(), getY(), getWidth(), getHeight() methods

I am writing a drag and drop application and got really confused because of some parameters. Please help to figure out. First of all, I read the documentation for the View class and got the following explanations. getX() : The visual x position of…
Carmine
  • 2,156
  • 3
  • 22
  • 48
14
votes
2 answers
1
2 3
30 31