android 动态加载视图,Android ConstraintLayout:如何将动态视图添加到另一个下方

我试图在约束布局的运行时将TextViews添加到另一个之下。但我总是只有一个文本视图,其余的隐藏在它后面。我尝试了几件事情,包括链接视图,但似乎没有任何工作。Android ConstraintLayout:如何将动态视图添加到另一个下方

private void method(int position)

{

ConstraintSet set = new ConstraintSet();

TextView textView = new TextView(getContext());

int textViewId = 100 + position;

//previousTextViewId = textViewId;

textView.setId(textViewId);

ConstraintLayout.LayoutParams layoutParams = new ConstraintLayout.LayoutParams(0, WRAP_CONTENT);

layoutParams.rightToRight = PARENT_ID;

layoutParams.leftToLeft = guideline_60.getId(); //Vertical GuideLine of 60%

layoutParams.rightMargin = 8;

textView.setLayoutParams(layoutParams);

if (Build.VERSION.SDK_INT < 23)

{

textView.setTextAppearance(getContext(), R.style.textStyle);

}

else

{

textView.setTextAppearance(R.style.textStyle);

}

textView.setBackgroundColor(backgroundColor);

textView.setText(categoryName);

textView.setGravity(Gravity.CENTER);

//markerLayout is the ConstraintLayout

markerLayout.addView(textView, position);

set.clone(markerLayout);

//set.addToVerticalChain(textView.getId(),previousTextViewId,PARENT_ID);

set.connect(textView.getId(), ConstraintSet.TOP, markerLayout.getId(), ConstraintSet.TOP, 60);

set.applyTo(markerLayout);

}

我期待看到这样的事情 -

t7c7v.png

2017-03-03

sku

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值