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

Gallery layout_height set to wrap_content in ListView

I have ListView with My Custom Adapter. The problem is, that gallery view is very hight, althought there is wrap_content in layout_height. How I can fix it? public class ListViewAdapter extends BaseAdapter { Context ctx; LayoutInflater…
0
votes
1 answer

Cannot resize LinearLayout in height

I have a LinearLayout inside of a Scrollview. After doing some animations, there is blank space at the bottom when I scroll down. So I want to resize the LinearLayout using this code ViewGroup.LayoutParams params =…
Luca Thiede
  • 3,229
  • 4
  • 21
  • 32
0
votes
1 answer

Proper Way of Changing View Properties at runtime

So i have a view which is inflated via Xml. That view has a subView, which i need to set a marginTop with a dynamic value like this: toolbar.getHeight() - 100 For this reason, i cannot set it to xml. I could do this: ?attr/actionBarSize but i need…
johnny_crq
  • 4,291
  • 5
  • 39
  • 64
0
votes
1 answer

Add a ViewStub programmatically to an RelativeLayout, than add a second ViewStub below the first

Hey I will shortly describe what I do in the code below: I create an ViewStub (Vs) and add it to the RelativeLayout (Rl). Then I want to add a new Vs to the same RL, so I create the stub2 and add it to rl. Then I reference to the Rl (which is…
0
votes
1 answer

Android ListView setLayoutParams causes clicking first item to hang

I'm setting the height of the rows in my ListView programmatically. However, after I do this, clicking the first item in my ListView hangs until I click a different item. Only then does it begin functioning. It works fine if I don't set the layout…
blurbs78
  • 23
  • 10
0
votes
0 answers

Child View invisible after addView() on API 16

I have a problem with Views, but only on API 16 :-( There is a CustomView, which looks like this:
Kelevandos
  • 7,024
  • 2
  • 29
  • 46
0
votes
1 answer

Keep on getting error when trying to get RelativeLayout.LayoutParams

I have this view I define the RelativeLayout, one that I want to manipulate in Java, like this ViewGroup parent = (ViewGroup) rootView .findViewById(R.id.rltv_layout); I want to…
Konayuki
  • 674
  • 1
  • 9
  • 21
0
votes
1 answer

Android View.getLayoutParams() leftMargin and topMargin give 0

I have a View in a RelativeLayout with layout_alignParentBottom and layout_alignParentRight attributes set to true like this :
nayakasu
  • 889
  • 1
  • 11
  • 32
0
votes
0 answers

java.lang.ClassCastException: android.widget.AbsListView$LayoutParams cannot be cast to android.widget.LinearLayout$LayoutParams

I am trying to put message n date below it in same bubble Messeage TextView. so i used LayoutParams to make bubble left or right. But I'm getting this error. FATAL EXCEPTION: main Process: com.rana.sahaj.myyu, PID: 18103 …
0
votes
1 answer

Getting the size of an inner layout in pixels

With the following Java and XML code, I was wondering how to retrieve the dimensions in pixels of an inner/child layout (LinearLayout, whereas the parent is RelativeLayout with paddings of 20dp) properly: Java code: public class TestActivity extends…
DaveNOTDavid
  • 1,753
  • 5
  • 19
  • 37
0
votes
3 answers

Android - How to make an AlertDialog narrower than standard?

I currently have the following code to build a wait dialog with a ProgressBar: LayoutInflater factory = LayoutInflater.from(TherapistActivity.this); View view = factory.inflate(R.layout.waitdialog, null); dialog = new…
0
votes
1 answer

Android custom LinearLayout : getParams return null

I try to create a custom LinearLayout which will act like a grid. I succeed to do so, and to have the aspect I want but I still have a problem. When I have only one rows. I want to change the layout_height attribute of my custom layout from…
0
votes
2 answers

Android layaout Params

I have a button with dimensions: btn1.width = 100; btn2.height = 150; I used the following code to resize: RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) btn1.getLayoutParams(); layoutParams.width =…
user3240604
  • 407
  • 1
  • 8
  • 22
0
votes
2 answers

Android: Can't align programmatically added edit text to top of screen

Hey so I am adding a custom edit text to my fragment and for some reason I can't get it to align with the top of the screen. It always ends up in the middle of the screen. "NotePad" edit text: public class LinedEditText extends EditText { …
Glenn Werner
  • 2,048
  • 2
  • 12
  • 16
0
votes
2 answers

Viewpager to fill the rest of the page

I am trying to resize a viewpager to the rest of the page. I have this globallayout listener: ViewTreeObserver viewTreeObserver = pager.getViewTreeObserver(); viewTreeObserver .addOnGlobalLayoutListener(new…
rosu alin
  • 5,674
  • 11
  • 69
  • 150