I have created a custom view named Graphview
. Here is the structure for the GraphView class.
public class GraphView extends View {
public GraphView(Context context, float[] values, String title, String[] horlabels, String[] verlabels, boolean type) {
super(context);
........
}
..................
.................
}
I have added the view in a tablerow using addview()
. It is working fine. Now I want to set height and width for the GraphView
. How to do that?
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.
spin12.setLayoutParams(new LinearLayout.LayoutParams(200, 120));
spin12
is your spinner and 200,120 is width
and height
for your spinner
.
You can set height and width like this:
myGraphView.setLayoutParams(new LayoutParams(width, height));
On Kotlin you can set width and height of any view directly using their virtual properties:
someView.layoutParams.width = 100
someView.layoutParams.height = 200
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);
Source: Stackoverflow.com