android - 如何在约束布局周围创建边框以及标题选项
问题描述
我需要实现如下风格
但是,我有一个约束布局,里面有很多子布局,它类似于一个编辑文本视图,具有通过锁定编辑其他值来编辑特定值集的功能。
现在我知道如何使用下面的代码在约束布局周围给出边框
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@android:color/transparent" />
<stroke
android:width="1dp"
android:color="#6B000000" />
<corners android:radius="4dp" />
</shape>
但是,我不知道如何像上图那样设置标题。
我试图将带有负边距/填充的 textview 放在下面,但它没有用
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#00000000"
android:fontFamily="sans-serif"
android:text="@string/title"
android:textColor="@color/logoDark"
android:textCursorDrawable="@drawable/cursor_style"
android:textSize="12sp"
android:paddingTop="-20dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
解决方案
以上所有答案都集中在创建新布局上。但你不应该这样做。只需在约束布局下方创建一个 TextView 即可。
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="sans-serif"
android:text="@string/time_range"
android:textColor="@color/logoDark"
android:textCursorDrawable="@drawable/cursor_style"
// Below are very important to achieve title on border
android:paddingStart="2dp"
android:paddingEnd="2dp"
android:layout_marginStart="10dp"
android:background="@color/cnstrbkg"
app:layout_constraintBottom_toTopOf="@+id/cnstLyt"
app:layout_constraintStart_toStartOf="@+id/cnstLyt"
app:layout_constraintTop_toTopOf="@+id/cnstLyt" />
textview的定位是非常非常重要的事情。更改它以将文本视图移动到您想要的任何位置。
推荐阅读
- node.js - Mongoose:尝试将嵌套对象字段设置为原始值“null”
- heroku - 如何取消 Heroku Review-app 上的冗余构建
- c - 我正在尝试将多个客户端与此服务器连接,但代码似乎不起作用>
- c++ - 将其他函数中的变量用于主函数 C++
- sql - 从表中选择不同的值
- c# - 为什么泛型类型定义的 BaseType 本身不是泛型类型定义?
- postman - AWS API 网关问题
- angularjs - 在 Javascript 中使用 Razor 更改 AngularJS “$http.post” URL
- bash - 使用特定模式重命名文件并修剪名称的其余部分 - bash
- kubernetes - 使用 istioctl 安装时在 Istio 1.4.0 中创建资源时超时