First get layout params using view. getLayoutParams(). Second then set the height and width value then last set the layout params of view.
You can set height and width like this:
myGraphView.setLayoutParams(new LayoutParams(width, height));
If you know the exact size of the view, just use setLayoutParams()
:
graphView.setLayoutParams(new LayoutParams(width, height));
Or in Kotlin:
graphView.layoutParams = LayoutParams(width, height)
However, if you need a more flexible approach you can override onMeasure()
to measure the view more precisely depending on the space available and layout constraints (wrap_content
, match_parent
, or a fixed size). You can find more details about onMeasure()
in the android docs.
you can set the height and width of a view in a relative layout like this
ViewGroup.LayoutParams params = view.getLayoutParams();
params.height = 130;
view.setLayoutParams(params);
On Kotlin you can set width and height of any view directly using their virtual properties:
someView.layoutParams.width = 100
someView.layoutParams.height = 200
spin12.setLayoutParams(new LinearLayout.LayoutParams(200, 120));
spin12
is your spinner and 200,120 is width
and height
for your spinner
.
This is a Kotlin based version, assuming that the parent view is an instance of LinearLayout
.
someView.layoutParams = LinearLayout.LayoutParams(100, 200)
This allows to set the width and height (100
and 200
) in a single line.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With