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

Android combining two LayoutParams

I am attempting to fix both the Width and the margins of a ProgressBar with layout params The following correctly sets the layout_margin int finalHeight = soundcloudImage.getHeight() / 8; int finalWidth = soundcloudImage.getWidth() /…
Master Zangetsu
  • 262
  • 7
  • 20
0
votes
0 answers

When changing the image resourse the image size changes

I have an OnclickListener in my Android app which changes the ImageResourse when clicking the element assigned to it, the problem is when changing the ImageResourse the size of it changes also(fills the height of the Layout and widen the width) and…
MRefaat
  • 515
  • 2
  • 8
  • 22
0
votes
1 answer

What is difference between .setGravity(...) method and getLayoutParams().gravity=x?

If you want to set the gravity of a View like LinearLayout programmatically, you have 2 ways: 1) LinearLayout.LayoutParams params = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.FILL_PARENT, …
Bob
  • 22,810
  • 38
  • 143
  • 225
0
votes
2 answers

Inserting TableRows into TableLayout programmatically - TextView inside TableRow won't display

Okay, so I'm trying to insert TableRows into a TableLayout programmatically every time a button is tapped. Each of these rows contain a TextView set to some String. My problem is, that although the TableRow is inserted successfully, the text within…
u3l
  • 3,342
  • 4
  • 34
  • 51
0
votes
1 answer

How to add a whole layout withing main layout in android

I've tried following code to add two layouts within main layout but this gives error while setting layout to frame and while adding it into view public class MainActivity extends Activity { FrameLayout rootLayout; FrameLayout…
Bhupesh
  • 477
  • 1
  • 8
  • 22
0
votes
2 answers

Adding "below" to Linear Layout LayoutParams

My main (highest in hierarchy) layout is a RelativeLayout. Within it, I am programmatically creating a LinearLayout. It must have the attribute of being "below" button1. I know how to use addRule() to add this to RelativeLayout.LayoutParams, but…
Wilson
  • 8,570
  • 20
  • 66
  • 101
0
votes
2 answers

How can I programmatically set button in right corner of edittext?

How can I programmatically set button in right corner of EditText? FrameLayout fl = new FrameLayout(this); lv.addView(fl); searchTxt = new EditText(this); fl.addView(searchTxt); btnSearch = new Button(this); I tried…
0
votes
0 answers

set layout margins dynamically

I have a vertical layout that contains 10 relative layouts. The UX team has prepared a background with horizontal lines so I have to fit the 10 relative layout elements dynamically on the screen. I have wrote the following code to set a listener to…
Simon
  • 509
  • 7
  • 25
0
votes
1 answer

How to create this UI programatically in android

The rectangle is the entire screen. The dotted line represents the center of the height and width. Each red line is an imageview and the green dot is the center of the imageview. Each imageview is equidistant from the neighbouring imageview and the…
adhithiyan
  • 168
  • 1
  • 9
0
votes
1 answer

Creating RelativeLayout with no XML file

I need to create this layout purely in Java and not in XML. This means I have no XML in Eclipse for this project. Right now my layout looks like this: You might not be able to tell from the picture but blocks 0, 1 and 3 are all on top of each…
Matt
  • 3,882
  • 14
  • 46
  • 89
0
votes
1 answer

Initializing and setting params of Button programatically

I am trying to initialize and set the height and width of 5 buttons programmatically. Below is my code, XML and LogCat. public class Puzzle extends Activity { Button btn1, btn2, btn3, btn4, btn5; @Override protected void…
Matt
  • 3,882
  • 14
  • 46
  • 89
0
votes
1 answer

android explaination addview & layoutparams during runtime

just want to know what happens when I set new layout params to a new instance of an ImageView and then add it on an empty layout. It seems like doing it reset the parent layout hosting the new ImageView and also reset position and size of every…
datamosh
  • 130
  • 3
  • 10
0
votes
3 answers

Android: How to get a view's height

For example, this is mButton:
nomnom
  • 1,560
  • 5
  • 17
  • 31
0
votes
1 answer

dynamically display textviews in a layout from arrays

I have 3 pieces of data I want to have displayed. All 3 are arrays of data. String[] debtName = new String[10]; String[] debtAmount = new String[10]; String[] debtPayment = new String[10]; I attempted the following in my TableLayout: public class…
jpgerb
  • 1,043
  • 1
  • 9
  • 36
0
votes
1 answer

android dim screen snippet does not work for me

I have the following code which is supposed to be very straight forward, but does not work : public class DisplayChapter extends ListActivity { ... @Override public boolean onOptionsItemSelected(MenuItem item) { switch…
Ivan
  • 6,388
  • 3
  • 24
  • 30