繁体   English   中英

如何使标题停留在边界线上的Cardview布局?

[英]How to make a cardview layout with title stay on top of the borderline?

我需要做一个看起来像这样的布局

在此处输入图片说明

已通过大量主题进行了研究,但仍无法找到制作方法

如果有人有想法或只是git源,请给我一些建议

您可以使用fieldset实现该目标。

<form>
  <fieldset>
    <legend>Personalia:</legend>
    Name: <input type="text"><br>
    Email: <input type="text"><br>
    Date of birth: <input type="text">
  </fieldset>
</form>

这是类似元素的垂直列表。 因此,您可以为他们使用Recyclerview。 在项目内,您可以使用新的“芯片”视图(请参阅https://medium.com/material-design-in-action/chips-material-components-for-android-46001664a40f )。

您只能设置cardview的背景颜色,不能直接设置边框颜色。 因此,请保留一个可绘制的文件作为背景,如下所示:

<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <stroke android:width="3dp" android:color="#abc" />
    <corners android:radius="20dp"/>
</shape>

您可以使用以下布局来实现所需的样式:

<RelativeLayout
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"
tools:context=".MainActivity">

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="100dp"
    android:layout_marginTop="15dp"
    android:background="@drawable/border"><!--You can add your necessary content within this layout-->
</RelativeLayout>
<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="#ffffff"
    android:layout_marginLeft="25dp"
    android:text="Sample Text"
    android:textSize="20sp"/>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM