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

"specified child already has a parent" error

I have a page that will display a weeks worth of scheduled games for a selected sport. The selected sport and week is stored within a XML file that is opened at the the start of the page. When I click on the next week link, a new week date value is…
user1172113
  • 1
  • 1
  • 1
0
votes
1 answer

Updating EditText LayoutParams from SurfaceView thread?

I have a EditText object created in the main activity in onCreate. I need to be able to change the layout parameters from a SurfaceView thread. Currently I am getting this error: android.view.ViewRoot$CalledFromWrongThreadException: Only the…
0
votes
2 answers

How to set flat/double values to layout parameters programmatically...?

I have Relative layout to which i want to set width 1.4dp How to do that.. If any have any idea please help. Thanks in advance...!
Noby
  • 6,562
  • 9
  • 40
  • 63
0
votes
1 answer

Tab Widget not displaying correctly onResume()

I'm using a custom TabWidget to display my tabs. The tabs work wonderfully when I first run the program. Everything looks beautiful. However, when I reload the program and, according the logcat, the onResume() method is called on my Tab Widget,…
Rymnel
  • 4,515
  • 3
  • 27
  • 28
0
votes
1 answer

nullPointerException on setLayoutParams

If I start app in portrait mode , it works fine. But if I start it into landscape mode then it gives nullPointerException when I try to resize my view by using setLayoutParams. piece of code @Override public void onCreate(Bundle…
GAMA
  • 5,958
  • 14
  • 79
  • 126
0
votes
1 answer

LayoutParams not showing

public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); LinearLayout ll=(LinearLayout)findViewById(R.id.linearlayout); for(int k=0;k<10;k++) { TableRow tr=new…
Gaurav
  • 667
  • 2
  • 13
  • 28
0
votes
1 answer

Android - setting layout params to TextView in millimeter

I believe you can set layout_width and layout_height to textview element dynamically using something like: LayoutParams lparams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.FILL_PARENT); centimeterLayout.addView(textview,…
jeffreyveon
  • 13,400
  • 18
  • 79
  • 129
0
votes
1 answer

Android - ImageView margins not appearing in LinearLayout

Right now, I'm struggling to accomplish something as simple as adding margin space between my child ImageViews within a custom LinearLayout (modified RadioGroup that is designed to take in a custom ImageView that implements Checkable, didn't…
0
votes
1 answer

Kotlin: Setting width using view.layoutparams.width doesn't work

I am trying to change width of a view programmatically, but it doesn't work, nothing changes. This is the code:
0
votes
3 answers

Hide System bars and go full screen in fragment

I have been trying to make a fragment fullscreen, but almost every answer on the web has deprecated methods. Even the android official site has a deprecated method Link. I'm using kotlin and after following this answer, I have tried this in…
0
votes
2 answers

RecyclerView items doesn't wrap the content

I'm facing this issue: I have recyclerview that shows images I've searched for but the items in recyclerview appears like their height is math_parent here's an example.. This is my activity_main.xml:
0
votes
1 answer

How to add an orange line under the imageView image programatically?

How do i add an orange line under the image before it's showed in the gallery? I want to mark the picture so it sticks out from all the other. I have tested all kinds of LayoutParams but need advice. See loots of explanations how to do this in the…
Erik
  • 5,039
  • 10
  • 63
  • 119
0
votes
0 answers

Set zero height to constraintLayout child programmatically

How can I set the height of a ConstraintLayout child to be 0dp? When I use layoutParams and do the following, ConstraintLayout thinks 0dp = match_parent val layoutParams = view.layoutParams.apply { this.height = newHeight …
mitsest
  • 305
  • 3
  • 19
0
votes
2 answers

Android Studio ImageView Change Only Width and Maintain Aspect Ratio

I've got an imageview, like this:
Evan
  • 1,892
  • 2
  • 19
  • 40
0
votes
0 answers

How can i set the view position in the center of the parent in java code?

I want to set the view position in the center of the parent when the button is clicked. How can i do that? Here is my condition, but when i click the button, the view goes to the upper left corner float pHeight = parent.getMeasuredHeight(); …
user15433749