【发布时间】:2019-08-28 06:42:49
【问题描述】:
我在约束布局中有一个视图(FrameLayout)
对于平板设备(仅限)我想要这个配置
1) its max height to say 100dp
2) It has to be wrap content
3) It has to be centered in its parent (vertically and
horizontally).
我有义务使用约束布局版本 1.0
我尝试将 Top-Bottom 用于其父约束,但它与其父约束的顶部对齐。
我尝试更改 app:layout_constraintHeight_default="wrap",但将其设置为 app:layout_constraintHeight_default="spread"` 违反了包装内容要求。
这是我的非平板电脑布局,我了解我想要制作平板电脑的所有内容,只有我会放在 values-sw600dp 资源文件夹下。
<?xml version="1.0" encoding="utf-8"?>
<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="match_parent"
android:background="@color/popup_view_scrim_color"
android:fitsSystemWindows="true"
tools:ignore="Overdraw">
<FrameLayout
android:id="@+id/viewToCenter"
android:layout_width="300dp"
android:layout_height="0dp"
android:layout_marginTop="@dimen/account_menu_popover_top_margin"
android:layout_marginBottom="@dimen/account_menu_popover_bottom_margin"
android:layout_marginLeft="@dimen/account_menu_popover_side_margin"
android:layout_marginRight="@dimen/account_menu_popover_side_margin"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHeight_default="wrap"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0">
</FrameLayout>
</android.support.constraint.ConstraintLayout>
我该如何解决这个问题?
【问题讨论】:
-
为什么是你的
height==0dp?ConstraintLayout中的0dp表示“匹配约束”。您是否尝试过使用android:layout_width="wrap_content"?
标签: android center android-constraintlayout layout-gravity