[英]Android ConstraintLayout programmatically connect but only work top to top
LinearLayout.LayoutParams navigationBarParams =
new LinearLayout.LayoutParams(0, (int)(BAR_DEFAULT_HEIGHT_DP * density) );
_navigationBar.setId(R.id.navigation_fragment_navigation_bar);
_navigationBar.setPadding(0, 0, 0, 0);
_navigationBar.setLayoutParams(navigationBarParams);
_navigationBar.setOrientation(LinearLayout.HORIZONTAL);
_navigationBar.setBaselineAligned(false);
_navigationBar.setWeightSum(6f);
_navigationBar.setElevation(20.0f);
ConstraintLayout con = (ConstraintLayout)_rootView.findViewById(_rootConstraintLayoutId);
con.addView(_navigationBar);
ConstraintSet set = new ConstraintSet();
set.clone(con);
set.constrainWidth(_navigationBar.getId(), 0);
set.connect(_navigationBar.getId(), ConstraintSet.TOP, con.getId(), ConstraintSet.TOP, 100 ); //work!
set.connect(_navigationBar.getId(), ConstraintSet.LEFT, con.getId(), ConstraintSet.LEFT,100 ); //not work!!
set.connect(_navigationBar.getId(), ConstraintSet.RIGHT, con.getId(), ConstraintSet.RIGHT, 100 ); //not work!!
set.applyTo(con);
I add LinearLayout to root ConstraintLayout. 我将LinearLayout添加到根ConstraintLayout。 and connect constraint TOP to TOP, LEFT to LEFT, RIGHT to RIGHT with all value 100. but only top value 100 is work.
并将所有条件都设为100的约束TOP到TOP,LEFT到LEFT,RIGHT到RIGHT连接起来。但是只有最高值100起作用。 not work left, right.
左,右不工作。 what wrong my code?
我的代码有什么问题?
임근영 Use Start and End instead on that way your view it will support different languages. 임근영以这种方式使用开始和结束,您的视图将支持不同的语言。
set.connect(boton.getId() , ConstraintSet.START , ConstraintSet.PARENT_ID , ConstraintSet.START , 80); set.connect(boton.getId(),ConstraintSet.START,ConstraintSet.PARENT_ID,ConstraintSet.START,80);
I know there is a bug reported on google for that. 我知道在Google上报告了一个错误。
android.support.constraint.ConstraintLayout android.support.constraint.ConstraintLayout
on that try removing it and use 在尝试删除它并使用
"LinearLayout" “的LinearLayout”
you will be able to change your orientation as you like. 您将可以根据需要更改方向。 by writing
通过写
andriod:oreiantation="horizontal" or andriod:oreiantation="vertiacl" andriod:oreiantation =“水平”或andriod:oreiantation =“ vertiacl”
its your choice 这是你的选择
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.