Help the program do the markup, as in the photo below. enter image description here

LinearLayout ALL = new LinearLayout(this); ALL.setOrientation(LinearLayout.VERTICAL); Toolbar.LayoutParams ALLParams = new Toolbar.LayoutParams(Toolbar.LayoutParams.MATCH_PARENT, Toolbar.LayoutParams.MATCH_PARENT); ALL.setLayoutParams(ALLParams); LinearLayout LL = new LinearLayout(this); LL.setOrientation(LinearLayout.VERTICAL); Toolbar.LayoutParams LLParams = new Toolbar.LayoutParams(Toolbar.LayoutParams.MATCH_PARENT, Toolbar.LayoutParams.MATCH_PARENT); LL.setWeightSum(6f); LL.setLayoutParams(LLParams); FrameLayout ladderFL = new FrameLayout(this); LinearLayout.LayoutParams ladderFLParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,Gravity.CENTER); ladderFL.setLayoutParams(ladderFLParams); ladderFL.setBackgroundColor(getResources().getColor(R.color.asad)); LinearLayout LL1 = new LinearLayout(this); LL1.setOrientation(LinearLayout.HORIZONTAL); Toolbar.LayoutParams LLParams1 = new Toolbar.LayoutParams(Toolbar.LayoutParams.MATCH_PARENT, Toolbar.LayoutParams.MATCH_PARENT); LL1.setWeightSum(6f); LL1.setLayoutParams(LLParams1); ladderFL.addView(ladder); LL.addView(ladderFL); LL1.addView(dummyView); LL1.addView(closeB); ALL.addView(LL1); ALL.addView(LL); RelativeLayout rl=((RelativeLayout) findViewById(R.id.relative)); rl.addView(ALL); 

I wrote but everything is not as it should, a lot of code, although I know that you can invest in a couple of lines, in general, I try to create markup in the first place.

  • First make the necessary markup in xml to understand what parameters you need to set. And only then all this will be transferred to the code. But I will say right away that without an additional twist in the center of the root relay, it will not be possible to center the liners. - eugeneek
  • @eugeneek if this is done first in xml, then double work is obtained. - Suvitruf
  • @Suvitruf I meant for educational purposes. It is clear that double work. - eugeneek

1 answer 1

Try this:

 @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); FrameLayout frameLayout = new FrameLayout(this); LinearLayout parentLinear = new LinearLayout(this); parentLinear.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 160, Gravity.BOTTOM)); parentLinear.setWeightSum(1f); parentLinear.setOrientation(LinearLayout.HORIZONTAL); LinearLayout linearLayoutLeft = new LinearLayout(this); linearLayoutLeft.setLayoutParams(new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.MATCH_PARENT, 0.5f)); linearLayoutLeft.setOrientation(LinearLayout.HORIZONTAL); linearLayoutLeft.setBackgroundColor(Color.RED); LinearLayout linearLayoutRight = new LinearLayout(this); linearLayoutRight.setLayoutParams(new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.MATCH_PARENT, 0.5f)); linearLayoutRight.setOrientation(LinearLayout.HORIZONTAL); linearLayoutRight.setBackgroundColor(Color.BLUE); parentLinear.addView(linearLayoutLeft); parentLinear.addView(linearLayoutRight); frameLayout.addView(parentLinear); setContentView(frameLayout); } 

Do not forget that 160 is the height in pixels, it is desirable to drive through the utilitarian class, where the density of the screen is taken into account. Tipo.

 AppUtils.dp(160) 

Dynamic layout is an actual theme, in one of the small projects they used Anvil, which is a typeset react of the layout, which is useful. https://github.com/zserge/anvil