Tag: android constraintlayout

Basic ConstraintLayout(工具栏,片段容器和底部导航)

我正在适应Android的Kotlin和ConstraintLayouts。 我试图有一个简单的布局,有一个工具栏和底部的导航视图。 这是我目前的XML: 不幸的是,我误解了一些东西,似乎无法获得片段容器来填充工具栏和底部导航之间的空间。 有人能把我引向正确的方向吗?

约束布局在布局文件中不可见…并获取错误,同时膨胀任何视图

我正在使用约束布局( android.support.constraint.ConstraintLayout )作为我的XML文件中的主布局。 当我们得到两个视图的布局(一个是用户视图和第二个是拖放视图,并提供他们之间的关系)。但我只得到一个窗口是完全空白,看起来像下面: 并在使用我的layout.View任何视图时得到这个错误,请检查下面的图像 我的布局文件如下: <?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/constraintLayout" android:layout_width="match_parent" android:layout_height="match_parent" tools:layout_editor_absoluteY="25dp" tools:layout_editor_absoluteX="0dp"> <ImageView android:id="@+id/image_shot" android:layout_width="0dp" android:layout_height="wrap_content" tools:layout_editor_absoluteY="0dp" tools:layout_editor_absoluteX="0dp" /> </android.support.constraint.ConstraintLayout> 我已经尝试了下面的解决方案,但它不适合我,请检查链接,我已经搜查 1.第一链接 2.第二链接 3.第三链接 请帮我解决这个问题。谢谢

在ConstraintLayout中使用组来侦听多个视图上的点击事件

基本上我想在一个ConstraintLayout中附加一个OnClickListener到多个视图。 在迁移到ConstraintLayout之前,我可以添加一个侦听器的布局内的视图。 现在,它们与ConstraintLayout下的其他视图位于同一图层上。 我试图将视图添加到android.support.constraint.Group并以编程方式添加一个OnClickListener。 group.setOnClickListener { Log.d("OnClick", "groupClickListener triggered") } 然而,这似乎并不像ConstraintLayout版本1.1.0-beta2 我做错了什么,有没有一种方法来实现这种行为,或者我需要将侦听器附加到每个单个视图?

如何以编程方式在约束布局中添加视图?

我正在设计下面的布局 <android.support.constraint.ConstraintLayout android:id="@+id/before_breakfast_option" android:layout_width="match_parent" android:layout_height="wrap_content"> <TextView android:id="@+id/diabetes_text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="16dp" android:layout_marginStart="16dp" android:text="water" android:textAppearance="@style/TextAppearance.AppCompat.Medium" android:textColor="@color/black" app:layout_constraintBaseline_toBaselineOf="@+id/toogle_diabeties" app:layout_constraintLeft_toLeftOf="parent"/> <TextView android:textColor="@color/black" android:text="almonds" app:layout_constraintTop_toTopOf="parent" android:id="@+id/toogle_diabeties" app:layout_constraintRight_toRightOf="parent" android:layout_width="wrap_content" android:layout_height="wrap_content"/> </android.support.constraint.ConstraintLayout> 使用下面的代码: var textView= TextView(this@DietStepFive) textView.id=100 textView.text="water" textView.background=ContextCompat.getDrawable(this@DietStepFive,R.drawable.rectangle_diet) textView.setTextColor(ContextCompat.getColor(this@DietStepFive,R.color.black)) var textView1= TextView(this@DietStepFive) textView1.id=101 textView1.text="almonds" textView1.background=ContextCompat.getDrawable(this@DietStepFive,R.drawable.rectangle_diet) textView1.setTextColor(ContextCompat.getColor(this@DietStepFive,R.color.black)) var constraintset= ConstraintSet() constraintset.clone(before_breakfast_option) //left to left of constraintset.connect(textView.id,ConstraintSet.LEFT,ConstraintSet.PARENT_ID,ConstraintSet.LEFT,0) //baseline constraintset.connect(textView.id,ConstraintSet.BASELINE,textView1.id,ConstraintSet.BASELINE,0) //right to right of […]