在我的应用程序中,我想要一些 subview 忽略父 View 填充。
例如:
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="86dp"
android:clipToPadding="false"
android:padding="8dp">
<TextView
android:id="@+id/history_restart"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_marginBottom="-8dp"
android:layout_marginTop="-8dp"
android:gravity="center"
android:paddingLeft="27dp"
android:paddingRight="27dp"
android:text="@string/history_restart_action_text"
android:textColor="@color/colorAccent"
android:textSize="@dimen/normal_text_size"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
试过了,但没有用:(
最佳答案
这是不可能的。您的父 View 具有固定的高度。添加填充意味着它将分配给其子项的最大高度将是 86dp - 2 * 8dp = 70dp
.使用负边距只会移动您的 View 。它不会改变它得到的高度。所以永远不会填父。
您必须放弃 padding 属性,而是在布局内的每个其他 View 上使用边距。
关于android-layout - 如何忽略子元素中的 ConstraintLayout 填充,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41116524/