android - ConstraintLayout 子项的边距不显示?

标签 android android-constraintlayout

我正在为我的应用程序使用 Android 的新 ConstraintLayout,但我一直遇到元素边距出现的问题。作为引用,我在我的 ConstraintLayout com.android.support.constraint:constraint-layout:1.0.0-beta4 的 gradle 文件中使用以下行。我的布局中的代码如下。

<android.support.constraint.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:paddingStart="@dimen/activity_horizontal_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/post_vertical_padding"
    android:paddingEnd="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingBottom="@dimen/post_vertical_padding"
    android:background="?android:attr/selectableItemBackground">

    <TextView
        style="@style/TitleText"
        android:id="@+id/post_type"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="@dimen/post_line_vertical_padding"
        android:layout_marginEnd="@dimen/post_type_horizontal_padding"
        android:layout_marginRight="@dimen/post_type_horizontal_padding"
        app:layout_constraintLeft_toRightOf="@id/poster_profile_pic"
        app:layout_constraintTop_toTopOf="parent" />

    <TextView
        android:id="@+id/poster_name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_constraintLeft_toRightOf="@id/post_type"
        app:layout_constraintBaseline_toBaselineOf="@id/post_type" />

</android.support.constraint.ConstraintLayout>

最佳答案

  1. 如果使用paddingStart,则不需要paddingLeft
  2. app:layout_constraintLeft_toRightOf="@id/poster_profile_pic" 此处没有 ID 为 poster_profile_pic
  3. 的 ImageView
  4. android:layout_marginBottom 除非您包含 constraintBottom_toBottomOf="parent"
  5. ,否则将不起作用
  6. android:layout_marginRight 应该是 android:layout_marginLeft 但是在 poster_name 因为 poster_nameapp: layout_constraintLeft_toRightOf="@id/post_type"

关于android - ConstraintLayout 子项的边距不显示?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41354255/

相关文章:

android - 如何使 GridLayoutManager 中的某个项目的高度相对于另一个项目进行调整?

android - 在约束布局中隐藏组内的单个 View

java - 为什么这是一个无效的 smali 寄存器?

android - 为什么迁移到 android bundle 后用户数据变大了?

android - 如何在 TextView 中显示 <ruby> 元素?

java - 如何将标签参数作为 (Mat) 从 Java 中的 OpenCV 传递到面部识别器?

android - AudioTrack 的内存泄漏

android - 不同屏幕尺寸的约束布局

android - 使用 XML 向约束布局中的 TextView 添加边距

Android ConstraintLayout @dimens 替换为硬编码值