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
0
votes
0 answers

Weird issue in custom view onMeasure

I have a custom view extended from RelativeLayout where the size should be square, and a background image with match_parent for it's width and height as it's child. There is also a button that should be centered horizontally and aligned with the…
0
votes
1 answer

Two ways of specifying the height of an android Layout?

Im having problems specifiying the height of a relative Layout. From what i understand, these two blocks of code should be equivalent (myLayout is a RelativeLayout that i defined in XML, with an initial height of "0dp", and it's parent is also a…
katzenhut
  • 1,742
  • 18
  • 26
0
votes
2 answers

Android set LeftMargin doesn't work on some devices

I've coded a Drag and drop behaviour for my Android application. So far it works perfectly on my HTC One and on my Samsung S3. Basically, it just sets the leftMargin and the topMargin on the view to move. When I try it on a Xperia Arc S, I can set…
Manitoba
  • 8,522
  • 11
  • 60
  • 122
0
votes
1 answer

getLayoutParams for LinearLayout under ScrollView not working

I have a LinearLayout and I controlled the height of this layout using getLayoutParams previously and it was working beautifully. Now I want the layout to be scrollable so I placed it under a ScrollView. Now for some reason the getLayoutParams…
0
votes
1 answer

Programmatic Margin for LinearLayout is ignored

I have an Android layout:
Vincent Ketelaars
  • 1,069
  • 1
  • 14
  • 35
0
votes
1 answer

How to use java to scale an imageview in the Android SDK?

I'm having trouble scaling an imageview in java in the Android SDK. I feel like this should be a relatively simple task but I can't seem to find an answer online that isn't using features that have been deprecated or otherwise appear overly…
user3488148
  • 59
  • 1
  • 8
0
votes
0 answers

Changing RelativeLayout - the height changes but not width

I have a relative layout that will expand / collapse - so I increase/decrease the height when a user taps on it. I'm using this code RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) view.getLayoutParams(); params.height =…
Alin
  • 1,044
  • 6
  • 20
  • 42
0
votes
3 answers

Changing existing parameters in a relative layout

I have following relative layout:
deimos1988
  • 5,896
  • 7
  • 41
  • 57
0
votes
1 answer

How to set TextView Dynamically left of paraent?

here is my code i got error params is null viewDynamic = new TextView(getApplicationContext()); RelativeLayout relativeLayout = (RelativeLayout) findViewById(R.id.relative); RelativeLayout.LayoutParams params =…
0
votes
2 answers

Alternative for 'addRule(int)' in ActionBar.LayoutParams like addRule in RelativeLayout.LayoutParams?

My code below works when placed in a class extending Activity class but addRule gives compile error saying it is undefined when I am extending ActionBarActivity. Error: The method addRule(int) is undefined for the type…
user1406716
  • 9,565
  • 22
  • 96
  • 151
0
votes
2 answers

ALIGN_PARENT_BOTTOM not working with my icon

I am trying to define a linearlayout at the bottom of a relative layout programmatically, so I am using ALIGN_PARENT_BOTTOM. But the layout created appearson the top of my screen as if I haven't define its position. Here is java code : final…
akari
  • 617
  • 1
  • 11
  • 32
0
votes
1 answer

Changing from ArrayAdapter with a textView to ArrayAdapter with LinearLayout. Class cast exception

My code is currently using an ArrayAdapter with a single TextView in layout file, and everything works well. My current layout is as follows…
0
votes
1 answer

Resizing Button in a TableLayout, Dynamically (Android)

Alright, I have searched for its solution But unable to find it. The Question is simple. There is a TableLayout in Android, I am adding few Rows in it. In the Last Row, I am adding a button. Now, the problem is the size of the button is not…
0
votes
0 answers

Are layout params Height and Width units the same as the coordinates x and y?

I am having some problems with setting a view's height: It seems that the number that I set on the LayoutParams does not correspond to the x and y coordinates on the screen. For example: when I set a View's height to 10 and then set another view's y…
Sochimickox
  • 135
  • 1
  • 2
  • 9
0
votes
1 answer

Changing the alignment of a TextView using LayoutParams Not working

I want to use this code to change the alignment of my textView in the layout programmatically. RelativeLayout.LayoutParams params =…