简体   繁体   English

Android ConstraintLayout以编程方式进行连接,但只能自上而下地工作

[英]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.

相关问题 Android:如何以编程方式仅舍入位图的顶角? - Android: how to programmatically round only top corners of a bitmap? 以一种不错的方式使用 ConstraintLayout 时,如何在顶部的 Android 中显示 Snackbar - How to show a Snackbar in Android on the top when using ConstraintLayout in a nice way Android以编程方式在按钮的右上角添加图片 - Android add a picture in the top right of a button programmatically Android:约束布局以编程方式设置约束顶部? - Android : Constraint Layout Set Constraint top programmatically? 如何在 ConstraintLayout 中将 ImageView 放在 CardView 之上 - How to put ImageView on top of CardView in ConstraintLayout 在 Android (java) 中以编程方式在 ConstraintLayout 中居中 TextView - Centering TextView in ConstraintLayout programmatically in Android (java) 以编程方式设置百分比宽度约束布局 Android - set percent width constraintlayout Android programmatically ConstraintLayout将边距底部应用到视图,也将其应用到视图顶部 - ConstraintLayout applying margin bottom to a view, also applies it to the top of the view 始终排在最前面,仅适用于应用 - Always on top only for application Android将类顶部的元素声明为私有元素,或在最终创建时声明-仅用于onclicklistener - Android declare element at top of class as private or in on create as final - only for onclicklistener
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM