- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试创建一个布局,其中各种数据由一条线( View )分隔,但该设计要求与该线的顶部和底部间距相等。我正在尝试使用边距来完成此操作,但没有得到预期的结果。基于official documentation ,只要为边缘方向设置了约束,就应该遵守它们。出于某种原因,上边距给了我们正确的间距,但是下边距根本没有给出任何间距。我创建了一个示例,其中仅包含要重现的相关布局 axml,以及足够大的边距以可视化问题:
<?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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="20dp">
<TextView android:text="NAME"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/account_name_label"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
/>
<TextView android:text="Your Name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/account_name"
app:layout_constraintTop_toBottomOf="@+id/account_name_label"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
/>
<View
android:id="@+id/line1"
app:layout_constraintTop_toBottomOf="@+id/account_name"
app:layout_constraintBottom_toTopOf="@+id/account_joined_label"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
android:layout_width="0dp"
android:layout_height="1dp"
android:background="#000000"
android:layout_marginTop="100dp"
android:layout_marginBottom="100dp"
/>
<TextView android:text="JOINED"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/account_joined_label"
app:layout_constraintTop_toBottomOf="@+id/line1"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
/>
<TextView android:text="January 1, 2019"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/account_joined"
app:layout_constraintTop_toBottomOf="@+id/account_joined_label"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
/>
</android.support.constraint.ConstraintLayout>
现在,我可以将 android:layout_marginTop="100dp"
添加到行 View 之后的第一个 TextView 以“修复”这个问题,但是我想重用行 View 的样式,而无需不必担心记住要为行 View 之后的第一个 View 添加上边距。我错过了什么?
更新:布局应该如下所示:
最佳答案
您需要将 account_joined
的底部连接到 parent 的底部,将 account_joined_label
的底部连接到 account_joined
的顶部。所以你可以试试这个:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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="match_parent"
android:padding="20dp">
<TextView android:text="NAME"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/account_name_label"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toBottomOf="parent"/>
<TextView android:text="Your Name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/account_name"
app:layout_constraintTop_toBottomOf="@+id/account_name_label"
app:layout_constraintRight_toRightOf="parent" />
<View
android:id="@+id/line1"
app:layout_constraintTop_toBottomOf="@+id/account_name"
app:layout_constraintBottom_toTopOf="@+id/account_joined_label"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
android:layout_width="0dp"
android:layout_height="1dp"
android:background="#000000"
android:layout_marginTop="100dp"
android:layout_marginBottom="100dp"/>
<TextView android:text="JOINED"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/account_joined_label"
app:layout_constraintTop_toBottomOf="@+id/line1"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toTopOf="@+id/account_joined" />
<TextView android:text="January 1, 2019"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/account_joined"
app:layout_constraintTop_toBottomOf="@+id/account_joined_label"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toBottomOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
关于安卓约束布局 : Views not respecting margins,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56810032/
对于 Dictionary “返回项目的顺序未定义”。 我知道有 SortedDictionary ,但如果我只想要一本字典,按照我放入元素的顺序返回元素,最好的办法是什么? 我在想我应该使用 Lis
为什么 RelativeLayout 不换行内容?如果我删除最后一个与底部父级对齐的 View ,它就可以工作...
我正在研究一些关于 Respect Relational 的内容尽管阅读了所有文档,但最终还是出现了一个问题。我可以对主键列未命名为“id”的记录进行更新吗?例如: 我在主键名称中包含“tb_”前缀的
我正在尝试创建一个布局,其中各种数据由一条线( View )分隔,但该设计要求与该线的顶部和底部间距相等。我正在尝试使用边距来完成此操作,但没有得到预期的结果。基于official documenta
我正在尝试使用 css 在带有 background-image 的 a 元素上插入 Logo 图像。 但是,我无法让 a:before 框遵守 a 的填充。 下面代码片段中的第一个示例使用了 wid
真棒Respect Validation library带有许多内置验证器,如 string()、alpha() 等。我想将自定义验证器添加到库中,例如,我希望能够这样做: Validator::my
我在 Android Studio 中有一个项目,但我似乎无法弄清楚这个 gradle 问题。我的应用程序结构如下: app(模块)依赖于 crashlib(模块),crashlib 依赖于来自我在
122 PG class Student { char grade } 现在,我需要通过解析上面的 XML 来设置上面的 Student 对象的成绩值 XML 中的此 CVF 元素可以有两个值:P
我需要使用 display: table 使内容居中显示 这是我的代码:JSFIDDLE 我需要让“表格”适合所有屏幕。但是如果 centered 不仅仅是屏幕,表格会变得太大并且忘记 height:
好的,到目前为止还没有任何建议,所以可能还没有真正正确地总结; 如果我用 class="container" 绝对定位该部分使用仅适用于 的额外类或 ID , 它把自己定位在它相对定位的祖先 之外
我一直在使用Respect Validation用于表单验证 $app->post('/', function () use ($app) { $validator = v::key('na
我使用 Slim 3 Framework在我的项目中,我有一个包含 3 个输入的表单:'file'、'name'、'firstname'。 假设 $request 有我表单的数据输入,为了获取上传的文
我正在使用 Respect/Validation类,我有自定义规则 CustomRule() 可以正常工作: use Respect\Validation\Validator as v; // ...
我有一个名为 UserDegree 的 mysql 数据库表,当我尝试使用 Doctrine 导入回 PHP 时,它会生成一个模型名称 Userdegree,有没有办法解决这个问题? 我真的找不到任何
我在使用 xsl:apply-templates 时遇到问题。我正在尝试将模板应用于一个特定标签,但我看到了来自其他标签的文本。一个简单的xml文件:
我部署的 pod 正在执行不应中断的工作。 K8s 是否可能正在轮询一个端点关于更新准备情况,或者通知我的 pod 它即将关闭以便它可以按顺序处理事务然后声明自己准备好进行更新? 理想过程: 更新的
我有一个简单的模型,比如资源。而且我的用户少于 20 个,模型管理员用于记录请求。 问题是所有用户都可以看到模型管理站点中的所有记录。 可以将此行为更改为仅显示由同一用户创建的记录吗? 谢谢你的期待。
我想知道是否可以回显一个变量并根据其内容改变值的相应颜色?这不同于为回显值设置固定颜色。 例如: Status DB中的状态内容可以是: “高”- 红色字体, "Med"- 橙色字体, “低”- 蓝
我有多个测试类,每个测试类都有自己的 SetUp() 和 TearDown()。 据我所知,在 RUN_ALL_TEST() 之后运行测试用例的顺序是未知的。 我想在第一次调用 SetUp 之前启动服
在此代码段中,您可以找到带有装饰下划线的 h2 header ,它是使用 :after 伪元素实现的。一切都运行良好,直到我们有一个 float 图像应该出现在前面提到的 h2 的左侧:h2 将正确
我是一名优秀的程序员,十分优秀!