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

Adjusting layouts for different screen sizes for API 14-17, 17-30, 30+

EDIT 09.05.2021: In general, I would like to programatically adjust the LayoutParams of some Buttons depending on the display size of the smartphone by adjusting some geometry values in onCreate(). Apparently it's not quite that simple. Finally…
Dorian Feyerer
  • 258
  • 5
  • 14
0
votes
1 answer

get ConstraintLayout height and width

I want to make a method that computes the margin values based on the parent's height and width. The code below outputs -1 for both height and width. How can I get the parent's height and width properly? @RequiresApi(api =…
0
votes
2 answers

How can I loop this process? I want to shrink the size of a textview with each button click

How can I loop this process? I want to shrink the size of a textview with each button click. It will work for one button click, but will not shrink for each click. import androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; import…
0
votes
1 answer

Changing height and width of a fragment makes child views disappear

I'm adding new fragments dynamically to an existing fragment and I'm doing some calculation to infer the size of the new fragment. After getting the new size i change the layout params of that new fragment to match the calculated size and this is…
Itzik984
  • 15,968
  • 28
  • 69
  • 107
0
votes
2 answers

Aligning Button to the bottom of CardView

So I'm creating some CardViews inside a for loop and I want to add a Button to the bottom of each CardView. I'm setting the LayoutParams of the CardView like this RelativeLayout.LayoutParams params4 = new RelativeLayout.LayoutParams( …
user11751594
0
votes
1 answer

Android resize View Layout Params with pinch

I am making an app that adds stickers on photos and i want to resize the sticker with a pinch gesture. final ImageView newSticker = new ImageView(getApplicationContext()); newSticker.setLayoutParams(new…
Aleksakb24
  • 51
  • 3
0
votes
1 answer

Android overlay window on API 26+, WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY vs TYPE_PHONE

I have an application which shows floating overlay windows and it works fine. It uses WindowManager.LayoutParams.TYPE_PHONE for the windows however and it says that it's deprecated on API level 26. Some people online said how they get errors when…
0
votes
0 answers

Expand view from within a ScrollView to full screen

What I have is a ConstraintLayout, which contains a ScrollView as one of its children. Inside this scrollview there is a LinearLayout containing all the components in the scrollview, including a videoview (but to all effects you can consider it a…
sgtpotatoe
  • 340
  • 6
  • 17
0
votes
1 answer

TextView height is different depending on text when textSize it's the same. Why?

I noticed, that a TextView with the same textSize can have a different height depending on the String it is displaying. I disscovered it when paiting a simple TableLayout which has some TableRow items with some cells, each cell is a TextView. Those…
NullPointerException
  • 36,107
  • 79
  • 222
  • 382
0
votes
1 answer

Source not found Exception while setting layoutparameters

Hi I'm new to android world. I'm working on an application that supports arabic and english languages.So I made my design for english language in the xml and through the code when the user wants to work with arabic language I change the gravity of…
FAFI
  • 379
  • 2
  • 6
  • 21
0
votes
3 answers

Creating a button in Java, causes getLayoutParams to return null

I need to create a button in Java. Below is my code: Button b = new Button(MyClass.this); b.requestLayout(); LayoutParams lp = b.getLayoutParams(); lp.height = LayoutParams.WRAP_CONTENT; lp.width = LayoutParams.WRAP_CONTENT; …
lost_bits1110
  • 157
  • 1
  • 5
  • 18
0
votes
1 answer

setLayoutParams() is not working in API <= 23

I am trying to split a sentence into words and put the words into a RelativeLayout as TextViews, but when I set layoutparams to TextView, doesn't take effect in API 23 and older. It works fine from API 24 and newer only if I use…
Besart
  • 309
  • 1
  • 4
  • 22
0
votes
1 answer

Dynamically created Imageviews randomly begin setting width/height to 0, Don't know what else to try [Kotlin]

Thanks in advance :) Context I have a game that is running at ~120 FPS and it dynamically creates multiple imageviews that move around the screen. These imageviews last for 5 seconds and then are made invisible and the code stops interacting with…
Seth
  • 1
  • 1
0
votes
0 answers

Android Studio LayoutParams.weight not working

I currently use LayoutParams to set layout_width and layout_height programmatically: ViewGroup.LayoutParams lp = new ViewGroup.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 215); tvText.setLayoutParams(lp); Now I want so set the weight, but…
0
votes
1 answer

Changing LayoutParams.height does not change size fully on old Android

I have ConstraintLayout with WRAP_CONTENT height, in which i show/hide RecyclerView (or another ConstraintLayout) by changing it's height from 0 (MATCH_CONSTRAINT) to WRAP_CONTENT and back. It works perfectly, but only on Android 8.0 and higher.…
kanphis
  • 1
  • 2