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
2 answers

creating dynamic table in android

I am trying to create a table from a 2-D array of strings. However, I suck in creating views in code, so for some reason my image is never visible and my textviews won't break into multilines, instead they chop of the text. Also, I put id on every…
elwis
  • 1,395
  • 2
  • 20
  • 34
0
votes
1 answer

Android .LinearLayout$LayoutParams cannot be cast to .FrameLayout$LayoutParams

I have an issue with the following error popping up whenever I try to create a layout programmatically: E/AndroidRuntime: FATAL EXCEPTION: main Process: com.appdev.vaidas.RMA, PID: 7024 java.lang.ClassCastException:…
curiousdev
  • 626
  • 8
  • 24
0
votes
1 answer

How change time of screen activity in android app (always active, active while charging, normal)

I am writing app in android and I need to change time of screen activity. In settings I have 3 possible variants: 1) screen always active; 2) screen always active while charging; 3) normal screen activity (using default android user settings) For…
0
votes
1 answer

Moving an ImageView on tap (Android)

I'm trying to test out setting the position of an ImageView when the user taps on the GameView. Whenever I tap on the emulator, the app crashes without any error messages. Same result for when I try setX/setY and setTop/setLeft I can't figure out…
0
votes
1 answer

Android Studio - issue with manipulating Layouts/Views programmatically

I have a few issues with setting LayoutParams and other parameters of my layouts/views programmatically. I cannot specify these in a XML layout file because whether they appear depends on the data held in the database. The following is a function I…
curiousdev
  • 626
  • 8
  • 24
0
votes
1 answer

How to display multiple items in ActionBar programmatically (TextView and ImageButton)?

I have a TextView and ImageButton I want to display in my ActionBar. I am able to successfully render the TextView or the ImageButton, but not both. Either I'm running out room to fit both of them, I'm not understanding how LayoutParams work, or…
DevOpsSauce
  • 1,319
  • 1
  • 20
  • 52
0
votes
0 answers

A faster way of setting width and height than setLayoutParams?

I'm trying to write a code that resizes a view's width and height by animating it, and to do that, what I've done is getting LayoutParams of the view once, and every 16 ms get a width and a height value from an int[] and change the width and height…
SIMMORSAL
  • 1,402
  • 1
  • 16
  • 32
0
votes
1 answer

AbsListView$LayoutParams cannot be cast to LinearLayout$LayoutParams

I'm just not able to set LinearLayout parameters programatically. Everything I try, I get this exact exception. LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) outerLayout.getLayoutParams(); params.bottomMargin =…
orglce
  • 513
  • 2
  • 7
  • 19
0
votes
0 answers

use gridlayout programatically and set layoutparams (weight)

I set layoutparams with this syntax gridParams= new GridLayout.LayoutParams(GridLayout.spec( GridLayout.UNDEFINED,(float) 1.0), GridLayout.spec(GridLayout.UNDEFINED,(float) 1.0)); But it does not work…
hassan
  • 1
  • 4
0
votes
2 answers

GridView gravity won't change

I am trying to change the gravity of a GridView whenever I click a button but the app crashes when deployed. I'm not sure why this occurs when the GridView has been declared in the XML layout. Attempt to invoke virtual method…
wbk727
  • 8,017
  • 12
  • 61
  • 125
0
votes
2 answers

Changing the margins of a textView when binding the view

In my layout I have a TextView inside of a RelativeLayout like below:
mango
  • 5,577
  • 4
  • 29
  • 41
0
votes
0 answers

Child views added dynamically without calculated margin values inside RelativeLayout as holder

I tried adding views to RelativeLayout holder with assigning left margin to layout params. The views got added but margin was not given while adding, resulting in overlapping views . My Java method to dynamically add Card (child view): public void…
0
votes
1 answer

Set Layout Params for custom View

In XML I was creating a new Entity of SwipeDeck (customView) like this :
JVS
  • 2,592
  • 3
  • 19
  • 31
0
votes
0 answers

LayoutParams not working

I am programming an app which generates all of its layout programmatically. I am looking to place an array of ImageView[] depending on their index. But it looks like the LayoutParams doesn't do anything since all the ImageViews are being superposed.…
user7866810
0
votes
1 answer

Adjusting the location of an ImageView dynamically based on the location of a Button

I am trying to create an activity that will display an image on the onClick of a button. So far, I have successfully made my application fade the image in when you click the button, but I want the image to be displayed over the button that has been…
cjnash
  • 1,228
  • 3
  • 19
  • 37