大家。
我能够做到。
首先,我用 java 代码将旋转器放在活动上。 “以编程方式”。
public void initTest(){
spinner2 = new Spinner(this, Spinner.MODE_DROPDOWN);
spinner2.setAdapter(new ArrayAdapter(this, R.layout.spinner_item, datos));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
spinner2.setId(spinner2.generateViewId());
}
ConstraintLayout parentLayout = (ConstraintLayout)findViewById(R.id.main_activity);
parentLayout.addView(spinner2, 0);
ConstraintSet cs = new ConstraintSet();
cs.clone(parentLayout);
cs.setHorizontalBias(spinner2.getId(), 0.473F);
cs.setVerticalBias(spinner2.getId(), 0.484F);
cs.connect(spinner2.getId(), ConstraintSet.BOTTOM, parentLayout.getId(),ConstraintSet.BOTTOM);
cs.connect(spinner2.getId(), ConstraintSet.START, parentLayout.getId(),ConstraintSet.START);
cs.connect(spinner2.getId(), ConstraintSet.TOP, parentLayout.getId(),ConstraintSet.TOP);
cs.connect(spinner2.getId(), ConstraintSet.END, parentLayout.getId(),ConstraintSet.END);
// cs view id, else getId() returns -1
// connect start and end point of views, in this case top of child to top of parent.
// ... similarly add other constraints
cs.applyTo(parentLayout);
}
然后我调用问题开头的代码。
我希望它对很多人有用,并跳过新版本的这个错误。
Regards.