Android ConstraintLayout页边距不能正常工作
问题描述:
如图所示,视图框呈现在当前位置,但内容不是。文本视图以及图像视图呈现为没有任何边距。当我运行应用程序时,它们也没有正确渲染(第二幅图像)。我不知道是什么原因造成的。
Android ConstraintLayout页边距不能正常工作
编辑:我忘了,包括我的XML:
<?xml version="1.0" encoding="utf-8"?>
<com.example.android.stundenplanexample.dynamic_recyclerview.ExpandingCardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/card_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
card_view:cardCornerRadius="2dp"
card_view:cardElevation="2dp"
android:layout_margin="12dp">
<android.support.constraint.ConstraintLayout
android:id="@+id/constraint"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:layout_margin="8dp"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_weight="0"
android:src="@drawable/ic_expand_more_black_24dp"
android:id="@+id/card_expand_toggle"
tools:ignore="ContentDescription"
android:layout_marginTop="16dp"
card_view:layout_constraintTop_toTopOf="parent"
card_view:layout_constraintRight_toRightOf="parent"
android:layout_marginEnd="24dp" />
<TextView
android:layout_margin="8dp"
android:layout_weight="1"
android:textAppearance="@android:style/TextAppearance.Material.Medium"
android:textColor="?android:attr/textColorPrimary"
android:layout_width="42dp"
android:layout_height="wrap_content"
android:text="@string/card_expand_string"
android:id="@+id/textView3"
card_view:layout_constraintTop_toTopOf="parent"
android:layout_marginStart="16dp"
card_view:layout_constraintLeft_toLeftOf="parent"
android:layout_marginTop="16dp" />
<TextView
android:layout_height="wrap_content"
android:id="@+id/extra_information"
android:layout_width="wrap_content"
tools:text="ToleToleToleInfo"
card_view:layout_constraintLeft_toLeftOf="@+id/textView3"
android:layout_marginTop="8dp"
card_view:layout_constraintTop_toBottomOf="@+id/textView3"
card_view:layout_constraintBottom_toBottomOf="parent"
android:layout_marginBottom="16dp" />
</android.support.constraint.ConstraintLayout>
</com.example.android.stundenplanexample.dynamic_recyclerview.ExpandingCardView>
答
我看到一个明确的问题,一个潜在的问题。
的明确的问题是,你的textView3
指定这些属性:
android:layout_margin="8dp"
android:layout_marginTop="16dp"
android:layout_marginStart="16dp"
这不设置顶部/开始16DP和结束/底部8DP。它只会导致marginTop
和marginStart
属性被忽略。
潜在的问题是,您所指定
android:layout_marginStart="16dp"
,但不同时指定marginLeft
。如果要支持API 17之前的设备,则需要同时指定marginStart
和marginLeft
(假设您删除margin
属性)。
保证金没有手动设置,而是通过设计视图设置。无论如何,我会尝试,谢谢 – BBotMerlin
谢谢,那就是问题所在。我想我没有看到它,因为我通常使用CSS和HTML,在这里工作。 – BBotMerlin
你知道我可以在哪里报告这个错误(因为编辑器显然没有正确渲染它) – BBotMerlin