Questions tagged [android-layoutparams]

The base LayoutParams class just describes how big the view wants to be for both width and height. For each dimension, it can specify one of:

  • FILL_PARENT (renamed MATCH_PARENT in API Level 8 and higher), which means that the view wants to be as big as its parent (minus padding)
  • WRAP_CONTENT, which means that the view wants to be just big enough to enclose its content (plus padding) an exact number

There are subclasses of LayoutParams for different subclasses of ViewGroup. For example, AbsoluteLayout has its own subclass of LayoutParams which adds an X and Y value.

Useful links

123 questions
0
votes
0 answers

android custom layout parameters ClassCastException and what about the View?

Okay, here is what I am doing... I have two custom layouts: HandedLayout extends ViewGroup and HandedPathLayout extends HandedLayout So in the root layout, I have a custom LayoutParameters to accept a layout property, called handed. Here is the…
0
votes
1 answer

Android: cast conflict setting LayoutParams (cast to ActionMenuView error)

My Android app is targeted to Android 3.1 and has a mode where a different menu is loaded on the action bar, with also a spinner and some buttons. I get the following error: android.app.ActionBar$LayoutParams cannot be cast to…
0
votes
1 answer

How to set height and width and align button programatically?

I have to get the date picker dialog and time picker dialog in one dialog. For this I have a code in this the buttons are added to set the time and date and to switch between date and time picker dialog. I have set a drawable resourse to the buttons…
user6265109
0
votes
1 answer

Change size of only one item in GridView

public void onBindViewHolder(final ViewHolder viewHolder, final int position) { viewHolder.button.setText("button" + +position); if(position == 0){ RecyclerView.LayoutParams params = (RecyclerView.LayoutParams); …
0
votes
2 answers

Align text to right or to bottom depending on space

I have two textviews, and I want to align the second textview to right or to the bottom of the first textview depending on the space. The result should be something like: First case (single line): Text1 one line Text2 Second case (multi…
FVod
  • 2,245
  • 5
  • 25
  • 52
0
votes
2 answers

Equivalent of android:layout_above="@+id/foo"

In XML you can do: android:layout_above="@+id/foo" to make a element be above another element foo. How do I do this programatically? While RelativeLayout.LayoutParams can add the rule RelativeLayout.ABOVE that does not allow me to specify which…
Foobar
  • 7,458
  • 16
  • 81
  • 161
0
votes
0 answers

how to show images in different row and columns?

for (int i = 0; i <10; i++) { int count = i; iv_album[i] = new ImageView(this); iv_album[i].setImageDrawable(this.getResources().getDrawable(R.drawable.desimg)); iv_album[i].setPadding(0, 5, 5, 0); …
0
votes
3 answers

android correct padding between views programmatically

I programmatically created four Textviews and added it in my Linearlayout.my linearlayout has 216dp width and TextView which I created pro-grammatically has 48 dp width and height. I want to add padding between TextView. I wrote some code but I…
0
votes
1 answer

How to make explicitly set layout height be equal in all device sizes

In some part of my application I need to set explicitly the height of a layout. I have this code for that: ListView.LayoutParams lp = new ListView.LayoutParams(ListView.LayoutParams.MATCH_PARENT,…
jstuardo
  • 3,901
  • 14
  • 61
  • 136
0
votes
1 answer

How to set height of a layout after the layout was already created

I spent several hours trying to do this, but finally I gave up. I have a LinearLayout. Inside of it I have another LinearLayout that is initially hidden. When some condition occurs, I need that hidden layout to be shown and the containing layout to…
jstuardo
  • 3,901
  • 14
  • 61
  • 136
0
votes
2 answers

WindowManager.addView ontop(overlay) of soft key OR nav bar

I saw an app that overlays whole screen including nav bar (or soft-key that has back, home, etc.) today. it's CF.Lumen(requires android 4.4+) by chainfire. I just remembered this is NOT POSSIBLE on general approach and many SO answers told me. So I…
-1
votes
1 answer

Error - Attempt to invoke virtual method 'int android.graphics.Bitmap.getHeight()' on a null object reference

I'm trying to change the height and the width from fixed to match parent or wrap content when images are loaded into the recycler view https://stackoverflow.com/a/67860281/15537898 here is the answer I'm trying to implement but after it gives me…
user16125085
-1
votes
1 answer

Setting LayoutParams but its not working android

Trying to create a linear layout programmatically and setting its width and height by layout params. But it seems layout params isn't working. this is the code: // CREATING A NEW LINEAR LAYOUT PROGRAMMATICALLY LinearLayout linearLayout = new…
Arpit Chhabra
  • 193
  • 1
  • 12
-1
votes
1 answer

"Attempt to invoke virtual method on a null object reference" when trying to getLayoutParams of a CardView in a DialogFragment?

I'm trying to set the size of a CardView inside of a DialogFragment, but I get this error: java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.ViewGroup$LayoutParams android.support.v7.widget.CardView.getLayoutParams()'…
1 2 3
8
9