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

how to set both horizontal and vertical layout params programmatically

In xml file we can do; android:layout_gravity="center_vertical|right" I couldn't find how to set those params programmatically. I think something like this is not possible. FrameLayout.LayoutParams params = new…
efeyc
  • 2,122
  • 2
  • 27
  • 39
2
votes
0 answers

How do I copy and modify LayoutParams to set them on a programmatically created widget?

My goal is to programmatically create and add TextView widgets to a ConstraintLayout, positioned at different angles around a circle relative to another widget, ie using the circular layout constraint. In my activity.xml I add a TextView txtCentred…
2
votes
2 answers

Android ListView layout param set

I have a Listview in my xml. The structure of it like that:
dev_android
  • 8,698
  • 22
  • 91
  • 148
2
votes
1 answer

Android - VideoView ignore LayoutParams in HDMI mode

Here is part of my code: requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.board); RelativeLayout lView = (RelativeLayout) findViewById(R.id.RelativeLayoutMain); VideoView mVideoView = new…
niedved
  • 21
  • 1
2
votes
2 answers

changing the position of ImageView dynamically in android

all I need to change the position of a ImageView dynamically and iam using the following code int x=100,y=100; RelativeLayout.LayoutParams mparam = new RelativeLayout.LayoutParams((int)(LayoutParams.FILL_PARENT),(int)(LayoutParams.FILL_PARENT)); …
surendra
  • 2,217
  • 7
  • 34
  • 42
2
votes
1 answer

How to set margin to main ConstraintView in android?

I want to set margin to my main layout with programmatically. I use layout params as following code. val parMain = mainLayout?.layoutParams as ConstraintLayout.LayoutParams But i have some error like android.view.ViewGroup$LayoutParams cannot be…
Murat Çakır
  • 150
  • 1
  • 14
2
votes
4 answers

Constraint Layout can't set width or height to 0

How can i set real width or height to 0 in ConstraintLayout programatically via its LayoutParams since the fact that ConstraintLayot.LayoutParams.MATCH_CONSTRAINT = 0 ? I want to use in my code something like this: view.getLayoutParams().width =…
Vlad
  • 497
  • 7
  • 12
2
votes
1 answer

generate programmatically same layout with .xml file

i have a gridLayout filled with some imageviews in my xml file and i want to create a copy of the gridlayout programmatically .xml file
2
votes
1 answer

Views overlap in card view when creating views dynamically (programmatically)

I want to create two edit text fields dynamically inside a card view when a button is pressed in the layout. When I tried this, two edit text views overlap on each other at the same place, I tried some of the ways, still I don't know to solve…
karthik
  • 528
  • 4
  • 19
2
votes
0 answers

Android 7 & 8 Only - ClassCastException: LayoutParams cannot be cast to AbsListView$LayoutParams

I have a very odd problem that I'm looking into. I didn't write the original code, but I am investigate why its crashing now, all of a sudden. After looking at it, I don't see any reason for the crash. Also, it works perfectly in lower OS levels…
2
votes
1 answer

How to save generated ImageButton in Shared Preferences

I have a problem with saving the ImageButton in SharedPreferences. Basically, I have a special REFRESH button: bbutton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) {... } and when clicking on it, it…
2
votes
2 answers

Why editing LayoutParams size doesn't have the effect of a canvas size

I am working on slide menu view which extends SurfaceView but when I try to change size of the view a canvas does not change. For debug purpose, I am changing size of the view calling method: public void changeSize() { width += 10; …
lvl7
  • 31
  • 6
2
votes
1 answer

Android get height of a wrap content view inflated as 0dp

I'm currently working on animation that will grow up the view if the user clicks it. Basically, its a card that, when clicked, it will reveal the bottom content. For that, I'm extending Animation like this: Val collapseAnimation = object :…
johnny_crq
  • 4,291
  • 5
  • 39
  • 64
2
votes
3 answers

How to set the align parent right attribute of TextViews in relative layout programmatically

I have a relative layout which I am creating programmatically: RelativeLayout layout = new RelativeLayout( this ); RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, …
SoftIdea
  • 47
  • 1
  • 5
2
votes
0 answers

android WindowManager.LayoutParams y not working

I want the background below popupwindow getting dim.But the background red rectangle marked got dim too.This is not the result I wanted. Here's my code of setting background: public void setBackgroundAlpha(float bgAlpha) { Window window =…
HelloSilence
  • 935
  • 2
  • 7
  • 19