Android - Programmatically specify height and width of new ScrollView

后端 未结 3 1716
醉梦人生
醉梦人生 2021-02-10 02:27

I\'m new to Android and I\'m working through a tutorial on programmatically creating a layout instead of doing it through the xml, I\'m sorta stuck can someone advise please.

相关标签:
3条回答
  • 2021-02-10 03:19

    Try setting it up like this:

    home_scroll.setLayoutParams(new ViewGroup.LayoutParams(480, 800));
    home_scroll.addView(home_linear, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
    

    The linearlayout should now fill the scrollview.

    0 讨论(0)
  • 2021-02-10 03:20

    Did you try doing something like

    home_scroll.setLayoutParams(..,..);
    

    you can find these here

    setLayoutParams(ViewGroup.LayoutParams params) 
    Set the layout parameters associated with this view.
    
    0 讨论(0)
  • 2021-02-10 03:20

    Simple way you can give dinamic width and height:-

     LayoutParams layout = new LayoutParams(LayoutParams.WRAP_CONTENT,
                        LayoutParams.WRAP_CONTENT);
                layout.setMargins(screenWidth / 5, screenHeight - cardHeight - 30, 0, 0);
                tvConftxt.setLayoutParams(layout);
    
    0 讨论(0)
提交回复
热议问题