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

scrollview doesn't scroll setting height programmatically

I would start with my goal. What I want to achieve is to have layout which is 3 times bigger then real screen of phone. Right now I try to test my solution, but I have problem with scrolling. This is how look my layout:
MyWay
  • 1,011
  • 2
  • 14
  • 35
0
votes
0 answers

Android ViewPager height WRAP_CONTENT not working

I have a ViewPager in my application that act as a slider. My problem is I want to my view pager's size matches it's child size (the loaded image).
0
votes
1 answer

When creating TextView dynamically the second TextView is not appearing

I'm creating two TextViews in my LinearLayout using the code below. I'm using them this way to catch a touch event when the press this specified area of the screen super.onCreate(savedInstanceState); …
user616076
  • 3,907
  • 8
  • 38
  • 64
0
votes
2 answers

Inflating ImageButton programatically changes width & height params to wrap_content. Why?

In my app I'm using android.support.v7.widget.Toolbar. Left half of the toolbar always acts as back button. Right half is different for different activities. Sometimes it's just text, sometimes a button. So I inflate the right half with views…
Pranav Mahajan
  • 2,048
  • 2
  • 23
  • 36
0
votes
2 answers

Is there a way to change the nested layout parameters of android widget programatically?

I would like to know if there is any way to change the width and height of nested Layout in android widget xml programatically just like that of LayoutParams in normal activity? I'm planning to make a custom progress bar with the LineraLayouts hence…
silverFoxA
  • 4,549
  • 7
  • 33
  • 73
0
votes
1 answer

why does View.setLayoutParams can call ViewGroup.onSetLayoutParams which is protected?

when i was searching the android source code, i have found something i can not understand or bear. you can see all onSetLayoutParams in the frameworks source code bellow: ./base/core/java/android/widget/Toolbar.java: protected void…
Zion
  • 13
  • 4
0
votes
2 answers

Drag an an initially centered TextView around RelativeLayout in Android

So I'm messing around with interacting with touch events/gestures in Android. One of the first things I did was make a textview in a relativelayout that I can drag around. Java code is: public class draggystuff extends ActionBarActivity implements…
Sven
  • 55
  • 7
0
votes
0 answers

Set ImageView layout params by onTouch

I have successfully implemented onTouch resizing on EditText view, but the same code doesn't seem to be working on ImageView. My code is basically getting onTouch on bottom right corner of a view and then changing layout params of the view…
Alex
  • 881
  • 2
  • 10
  • 24
0
votes
1 answer

Make a view fill a wrap content parent layout

I am trying to add color coding of classes for my android app which organized HW. I am trying to do this by adding a bar on the side with the color of the class. In the image I want the whole layout to wrap the height of the text and then have…
Zander B
  • 247
  • 3
  • 15
0
votes
2 answers

Using LayoutParams on While loop Java, Android

It seems like I have a problem with java code where I want to use LayoutParams in while loop. So in this code, I thought it might be like this but not working. If is width and height of the image > 0 , then start looping by subtracting height and…
0
votes
2 answers

margins not set properlly in VIEW in android

Margins not set to the dynamically created view:- RelativeLayout.LayoutParams mDeleteBinLayoutParams = new RelativeLayout.LayoutParams(90, 90); mDeleteBinLayoutParams.setMargins(100, -20, 0, 10); final DeleteZone mDeleteZone = new…
Ankush Badlas
  • 111
  • 1
  • 9
0
votes
2 answers

Obtain width and height of a Layout

I have a FrameLayout, when I try to get its params like this: ViewGroup.LayoutParams params = cameraPreviewFrameLayout.getLayoutParams(); int layoutHeight = params.height; int layoutWidth = params.width; Here, layoutHeight is -2 and layoutWidth is…
svprdga
  • 2,171
  • 1
  • 28
  • 51
0
votes
1 answer

Android: RelativeLayout margin works but gets overridden

Problem Using RelativeLayout.LayoutParams and marginTop before setLayoutParams( params ). Works on all devices for half a second but some cases it bumps back to top. The view stays centered in the holding view on my Moto X 2014 running Lollipop but…
Jonas Borggren
  • 2,591
  • 1
  • 22
  • 40
0
votes
1 answer

setLayoutParams in ArrayAdapter in getView must set params only to one view

I want the last cell to have for example 300dp height. Here is my getView method @Override public View getView(int position, View convertView, ViewGroup parent) { View rowView = convertView; if (rowView == null) { LayoutInflater…
LamaUltramarine
  • 115
  • 1
  • 1
  • 7
0
votes
0 answers

how can I set the positon of a button and a point in one place in android?

I added a button and a point in my project and put the point and button in the relative layout and set them same params like this code: rllp = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT); rllp.topMargin = 0…