RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

Close
  • 主页
  • 系统&网络
    • 热门问题
    • 最新问题
    • 标签
  • Ubuntu
    • 热门问题
    • 最新问题
    • 标签
  • 帮助
主页 / 问题 / 770422
Accepted
keltkelt
keltkelt
Asked:2020-01-14 04:48:51 +0000 UTC2020-01-14 04:48:51 +0000 UTC 2020-01-14 04:48:51 +0000 UTC

表还是约束布局?

  • 772

我正在做我的第一个申请。我希望底部的两个计时器 - 始终位于两半的中间(水平)。换句话说,就好像它们在表格的两列的中间。破折号应该从底部开始,如图所示。
到目前为止,我只工作过ConstraintLayout,我已经筋疲力尽了。它在元素的边缘有一个锚点。那些。如果元素的大小发生变化,那么一切都会移动,并且元素本身不会留在原地。对我来说,例如,01 小时变为 1。我应该看什么方向?

在此处输入图像描述

android
  • 1 1 个回答
  • 10 Views

1 个回答

  • Voted
  1. Best Answer
    pavlofff
    2020-01-14T19:03:51Z2020-01-14T19:03:51Z

    要布局这样的布局,您不需要参考线(指导线)。

    我们在布局上放置三个参考线(右键单击可视化标记编辑器:Helpers -> Add vertical\horizo​​ntal Guidelines):两条垂直线(1 和 2)和一条水平线(3)。垂直的将屏幕分成 3 个相等的部分(33% 和 66%),水平的一个 - 上四分之一(25%)。要将参考线的位置更改为百分比,请单击圆圈。

    屏幕截图

    现在我们修复小部件。我们将左计数器的右边缘固定在第一条参考线上,左边缘固定在屏幕边缘(这样您就可以在屏幕末端画一条线)。在这种情况下,上底到第三条参考线,下上到第三条参考线。我们将属性android:gravity="right"设置为这些小部件,以便文本从右边缘开始。
    我们将右侧计数器的左侧连接到第二条参考线,右侧连接到屏幕边缘,顶部和底部连接到左下计数器的顶部和底部 - 所以它们将位于水平方向相同。
    使用链工具(鼠标右键:Center -> Center Verticaly)将按钮和文本均匀分布在剩余的垂直空间上。

    可以通过简单地为这些小部件提供一个带有破折号作为背景的 9 路径图像来完成计数器下的线条 - 这是最简单的选项(我不会在示例中这样做)。

    这是最后发生的事情:

    屏幕截图

    标记:

    <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.support.constraint.Guideline
            android:id="@+id/guidelineVertical"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            app:layout_constraintGuide_percent="0.33" />
    
        <android.support.constraint.Guideline
            android:id="@+id/guidelineVertical2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            app:layout_constraintGuide_percent="0.66" />
    
        <android.support.constraint.Guideline
            android:id="@+id/guidelineHorizontal"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            app:layout_constraintGuide_percent="0.25" />
    
        <TextView
            android:id="@+id/count1"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginBottom="16dp"
            android:gravity="right"
            android:text="01:00:15"
            android:textSize="21sp"
            app:layout_constraintBottom_toTopOf="@+id/guidelineHorizontal"
            app:layout_constraintEnd_toStartOf="@+id/guidelineVertical"
            app:layout_constraintStart_toStartOf="parent" />
    
        <TextView
            android:id="@+id/count2"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginTop="16dp"
            android:gravity="right"
            android:text="1:00:00"
            android:textSize="21sp"
            app:layout_constraintEnd_toStartOf="@+id/guidelineVertical"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="@+id/guidelineHorizontal" />
    
        <TextView
            android:id="@+id/count3"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:text="12:00:00"
            android:textSize="21sp"
            app:layout_constraintBottom_toBottomOf="@+id/count2"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="@+id/guidelineVertical2"
            app:layout_constraintTop_toTopOf="@+id/count2" />
    
        <Button
            android:id="@+id/button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button"
            app:layout_constraintBottom_toTopOf="@+id/text"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/count2" />
    
        <TextView
            android:id="@+id/text"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:text="Test text ..."
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/button" />
    
    </android.support.constraint.ConstraintLayout>
    
    • 4

相关问题

Sidebar

Stats

  • 问题 10021
  • Answers 30001
  • 最佳答案 8000
  • 用户 6900
  • 常问
  • 回答
  • Marko Smith

    是否可以在 C++ 中继承类 <---> 结构?

    • 2 个回答
  • Marko Smith

    这种神经网络架构适合文本分类吗?

    • 1 个回答
  • Marko Smith

    为什么分配的工作方式不同?

    • 3 个回答
  • Marko Smith

    控制台中的光标坐标

    • 1 个回答
  • Marko Smith

    如何在 C++ 中删除类的实例?

    • 4 个回答
  • Marko Smith

    点是否属于线段的问题

    • 2 个回答
  • Marko Smith

    json结构错误

    • 1 个回答
  • Marko Smith

    ServiceWorker 中的“获取”事件

    • 1 个回答
  • Marko Smith

    c ++控制台应用程序exe文件[重复]

    • 1 个回答
  • Marko Smith

    按多列从sql表中选择

    • 1 个回答
  • Martin Hope
    Alexandr_TT 圣诞树动画 2020-12-23 00:38:08 +0000 UTC
  • Martin Hope
    Suvitruf - Andrei Apanasik 什么是空? 2020-08-21 01:48:09 +0000 UTC
  • Martin Hope
    Air 究竟是什么标识了网站访问者? 2020-11-03 15:49:20 +0000 UTC
  • Martin Hope
    Qwertiy 号码显示 9223372036854775807 2020-07-11 18:16:49 +0000 UTC
  • Martin Hope
    user216109 如何为黑客设下陷阱,或充分击退攻击? 2020-05-10 02:22:52 +0000 UTC
  • Martin Hope
    Qwertiy 并变成3个无穷大 2020-11-06 07:15:57 +0000 UTC
  • Martin Hope
    koks_rs 什么是样板代码? 2020-10-27 15:43:19 +0000 UTC
  • Martin Hope
    Sirop4ik 向 git 提交发布的正确方法是什么? 2020-10-05 00:02:00 +0000 UTC
  • Martin Hope
    faoxis 为什么在这么多示例中函数都称为 foo? 2020-08-15 04:42:49 +0000 UTC
  • Martin Hope
    Pavel Mayorov 如何从事件或回调函数中返回值?或者至少等他们完成。 2020-08-11 16:49:28 +0000 UTC

热门标签

javascript python java php c# c++ html android jquery mysql

Explore

  • 主页
  • 问题
    • 热门问题
    • 最新问题
  • 标签
  • 帮助

Footer

RError.com

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

帮助

© 2023 RError.com All Rights Reserve   沪ICP备12040472号-5