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
1
vote
0 answers

Dynamically add layouts (Relative Layouts) beneath each other in Android

I am trying to create a method where each time I click a button, I want the screen to display a Relative Layout box below one that is currently there or create one at the top if there isn't one there and I want it to keep creating them below from…
1
vote
1 answer

Add Relative Layout below current Relative Layout programmatically in Android

I am trying to create a method where each time I click a button, I want the screen to display a Relative Layout box below one that is currently there or create one at the top if there isn't one there and I want it to keep creating them below from…
1
vote
0 answers

Wrong LayoutParams being passed down form my Custom ViewGroup

Ironically enough I stumbled on a problem when I answered another question The problem is that if I add a RelativeLayout as a child of my ICGridLayout the children of that RelativeLayout does not get the RelativeLayout.LayoutParams. This goes for…
Risch
  • 564
  • 7
  • 20
1
vote
1 answer

How to make Button square and resizable

I would like to make button (the one between two other buttons) Square. I tried to use following code: toggleButton = (ToggleButton) findViewById(R.id.activity_dictionary_toggleButton1); LinearLayout.LayoutParams toggleButtonLayoutParams =…
Marek
  • 3,935
  • 10
  • 46
  • 70
1
vote
1 answer

FrameLayout.LayoutParams works different on different Android OS / APIs

FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams((int)width, (int)height); lp.width = (int) (width * 0.75f); lp.height = (int) (height * 0.5f); lp.setMargins((int) width/8, (int) height / 4, (int) (width - width/8) , (int)…
Khulja Sim Sim
  • 3,469
  • 1
  • 29
  • 28
1
vote
1 answer

Add more views in a layout programmatically in Android

I'm doing a paint application where in I already have a button. But I want to add another button. When I do, it's overlapping the previous button. I'm kinda new to LayoutParams so I need your guidance in here. Please do check the code I'm working…
neknek mouh
  • 1,802
  • 8
  • 27
  • 58
1
vote
2 answers

Android - Resize parent and child view using layoutparams

Hello I've a custom view that can be resized and the view have many child inside it what I want to ask is how to resize the parent and the child together using layout params? how to do that? I already tried to get the width of the view using…
1
vote
1 answer

How does LayoutParams.addRule work?

I am building an application that will add views to a relative layout until stopped. My question is how does RelativeLayout.LayoutParams.addRule work? If I keep calling addRule will this create an ever growing list or does addRule check if a rule…
AJ72
  • 168
  • 1
  • 12
1
vote
2 answers

Android Set wrap_content to ImageView by java code prob

I have set a Bitmap to an ImageView and then want to set wrap_content for both width and height. imgSubsegment = (ImageView) findViewById(R.id.subsegment); ViewGroup.LayoutParams imageViewParams = new ViewGroup.LayoutParams( …
dev_android
  • 8,698
  • 22
  • 91
  • 148
1
vote
1 answer

How to set the layout_weight of a TextView in code?

I have looked around, but most of them don't make any sense. Some have a third parameter that does not exists in the Android docs, at least anymore. Anybody have any idea how to accomplish this? I have this so far: @Override public View…
Andy
  • 10,553
  • 21
  • 75
  • 125
1
vote
1 answer

Android: MarginLayoutParams not working well on all phones

I have a fullscreen view which I partially move in and out from the phone screen, let's say to the half of the screen. To do this I am using MarginLayoutParameters to set the top margin to half of the screen, or to 0 in case I want it to be fully…
htafoya
  • 18,261
  • 11
  • 80
  • 104
1
vote
4 answers

GridView.LayoutParams to be the same in different screen sizes, is it possible?

I made a Grid View with 6 columns and 60 rows. Where I can add, move and erase images. But I'm having trouble to set the distance between columns (I don't want any space between columns). Since it will change deppending on screen size. I set it up…
R-Roadster
  • 125
  • 2
  • 4
  • 10
0
votes
1 answer

Android customlayout children not gettting measured height and width

I have implemented and activity (called HomeScreenActivity) that consists of two fragments. One of them displays a list of items, and the other displays the details of the selected item. The details fragment (ResumeFragment in my code) consists of a…
Anders Nysom
  • 101
  • 8
0
votes
1 answer

whats better, giving hard coded height or using weight parameter to set View parameters..?

I usually give fixed height in order to avoid views getting overlapped on orientation change, But is giving weight is better than this..?, share it if there are better ways to give LayoutParameter. Thank you.
ngesh
  • 13,398
  • 4
  • 44
  • 60
0
votes
1 answer

LinearLayout (dynamically) withLayoutParams (int , int) get invisible

When I set layout params text checkbox go invisible. I'd Like This visible. Thank Y LayoutParams lparams = new LayoutParams(30, 60); LinearLayout layoutCb = new LinearLayout(this); CheckBox checkbox =…
user1211927
  • 61
  • 1
  • 3