相关疑难解决方法(0)

如何将约束布局包含到另一个约束布局中并在每个布局之间设置约束

我正在使用constraintLyout v 1.0.1.

我想在我的xml中包含一个与我的全局布局的一部分相对应的子ConstraintLayout(它本身就是一个ConstraintLayout).我将布局分成两个xml,以便在其他地方使用此子部分

我尝试了这个但是我无法控制将子约束布局放在父级中的位置.我想知道是否必须将所有内容放在同一个xml文件中,或者它们是否是使用单独文件的解决方案.

tmp_1.xml

<android.support.constraint.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >
    <TextView
        android:id="@+id/label"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="LABEL1"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        android:layout_marginTop="16dp"
        />
    <TextView
        android:id="@+id/label_2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="LABEL2"
        app:layout_constraintStart_toStartOf="@id/label"
        app:layout_constraintEnd_toEndOf="@id/label"
        app:layout_constraintTop_toBottomOf="@id/label"
        android:layout_marginTop="16dp"
        />

    <include layout="@layout/tmp_2" />
</android.support.constraint.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)

tmp_2.xml

<android.support.constraint.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    >
    <TextView
        android:id="@+id/view_80"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="80th element"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        android:layout_marginTop="10dp"
        android:layout_marginStart="12dp"
        />
</android.support.constraint.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)

结果是此实际结果

但我希望它成为预期的结果

我试过这个,但它不起作用

<include 
    app:layout_constraintTop_toBottomOf="@id/label_2"
    layout="@layout/tmp_2" />
Run Code Online (Sandbox Code Playgroud)

我很乐意有你的解决方案,

谢谢

xml android include android-layout android-constraintlayout

42
推荐指数
2
解决办法
2万
查看次数

使用kotlin android扩展在不同的布局中引用具有相同id的视图

在我的Android项目中,我有两个布局:num_info和num_info_pack.两者都有id"circle"的视图.所以我认为通过layout_name.circle引用这些视图可以解决问题:

val inetView = activity.layoutInflater.inflate(R.layout.num_info_pack, parent, false)
    inetView.circle.setBackgroundResource(background)
Run Code Online (Sandbox Code Playgroud)

但圆圈用红色加下划线,它说:

过载分辨率模糊.所有这些功能都匹配.

public val View.circle:查看!在kotlinx.android.synthetic.main.num_info_pack.view中定义

public val View.circle:RelativeLayout!在kotlinx.android.synthetic.main.num_info_inet_plus_pack.view中定义

如果我特意说inetView.circle,为什么我在谈论哪个圈子?

android kotlin kotlin-android-extensions

8
推荐指数
3
解决办法
2063
查看次数