|
|
爱听歌的草稿本 · Oracle GraalVM ...· 4 月前 · |
|
|
憨厚的可乐 · BEA WORKSHOP 中的 AJAX 编程· 4 月前 · |
|
|
道上混的领结 · 从多个文件上的grep搜索中获取最后一行开发者社区· 3 月前 · |
|
|
安静的包子 · JavaScript中onclick事件传递 ...· 3 月前 · |
|
|
怕考试的木耳 · 软件分享库合集链接汇总推荐_蓝奏云软件分享链 ...· 1 年前 · |
|
|
精明的日记本 · 江西省发布第三批非法集资严重失信人名单 ...· 1 年前 · |
|
|
奔放的梨子 · Creating Word ...· 2 年前 · |
|
|
奔跑的苦咖啡 · 地藏菩萨本愿经讲记(第十三卷)· 2 年前 · |
|
|
愤怒的菠萝 · 异兽魔都(林田球创作的系列漫画)_搜狗百科· 2 年前 · |
我在ConstrainLayout中的视图如下所示。
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxWidth="260dp"
android:textColor="#FFF"
android:textSize="16sp"
app:layout_constraintLeft_toLeftOf="@+id/parent"
app:layout_constraintTop_toBottomOf="@id/message_date"
android:id="@+id/text_main"
/>
基于某些条件,我想在recycleViewHolder中以编程方式将视图更改为
app:layout_constraintLeft_toLeftOf="@+id/parent"
或
layout_constraintLeft_toRightOf="@+id/parent"
。
发布于 2017-01-16 16:55:18
下面是一个使用java代码在父视图底部设置按钮的示例:
ConstraintLayout constraintLayout;
ConstraintSet constraintSet;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
constraintLayout = (ConstraintLayout) findViewById(R.id.activity_main_constraint_layout);
Button button = new Button(this);
button.setText("Hello");
constraintLayout.addView(button);
constraintSet = new ConstraintSet();
constraintSet.clone(constraintLayout);
constraintSet.connect(button.getId(), ConstraintSet.LEFT, constraintLayout.getId(), ConstraintSet.RIGHT, 0);
constraintSet.constrainDefaultHeight(button.getId(), 200);
constraintSet.applyTo(constraintLayout);
}
为了达到这样的效果,
app:layout_constraintLeft_toLeftOf="@+id/parent"
您的java代码应该如下所示
set.connect(YOURVIEW.getId(),ConstraintSet.LEFT,ConstraintSet.PARENT_ID,ConstraintSet.LEFT,0);
为了达到这样的效果,
layout_constraintLeft_toRightOf="@+id/parent"
你的java代码应该是这样的,
set.connect(YOURVIEW.getId(),ConstraintSet.LEFT,ConstraintSet.PARENT_ID,ConstraintSet.RIGHT,0);
这里,我假设
android:id="@+id/parent"
是父ConstraintLayout的id。
发布于 2020-04-25 18:15:23
constraintSet =新ConstraintSet();以此类推
不管怎么说对我来说都不管用。
解决方式
LayoutParams layoutParams = (LayoutParams) viewToChange.getLayoutParams();
layoutParams.leftToLeft = anotherViewId;
layoutParams.rightToRight =anotherViewId;
layoutParams.topToTop = anotherViewId;
layoutParams.bottomToBottom = anotherViewId;
layoutParams.startToStart =anotherViewId;
layoutParams.endToEnd = anotherViewId;
viewToChange.setLayoutParams(layoutParams);
发布于 2018-11-27 21:37:16
使用
id
class MyLayout(context: Context) : ConstraintLayout(context) {
fun show() {
val view = ImageView(context)
addView(view)
val params = view.layoutParams as ConstraintLayout.LayoutParams
|
|
憨厚的可乐 · BEA WORKSHOP 中的 AJAX 编程 4 月前 |
|
|
道上混的领结 · 从多个文件上的grep搜索中获取最后一行开发者社区 3 月前 |
|
|
奔放的梨子 · Creating Word Application using Excel VBA: Run-time error '429': ActiveX component can't create obje 2 年前 |
|
|
奔跑的苦咖啡 · 地藏菩萨本愿经讲记(第十三卷) 2 年前 |
|
|
愤怒的菠萝 · 异兽魔都(林田球创作的系列漫画)_搜狗百科 2 年前 |