简体   繁体   English

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

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

I need to make a layout which look like this 我需要做一个看起来像这样的布局

在此处输入图片说明

Have been researched through alot of topic but still couldn't find out the way how to make it 已通过大量主题进行了研究,但仍无法找到制作方法

If anyone have an idea or just a git source please give me some advice 如果有人有想法或只是git源,请给我一些建议

you can use fieldset to achive that goal. 您可以使用fieldset实现该目标。

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

This is a vertical list of similar elements. 这是类似元素的垂直列表。 So you can use Recyclerview for them. 因此,您可以为他们使用Recyclerview。 Inside an item you can use new Chip view (see https://medium.com/material-design-in-action/chips-material-components-for-android-46001664a40f ). 在项目内,您可以使用新的“芯片”视图(请参阅https://medium.com/material-design-in-action/chips-material-components-for-android-46001664a40f )。

You can only set background color of cardview, cannot directly set border color. 您只能设置cardview的背景颜色,不能直接设置边框颜色。 So, keep a drawable file for background as follows : 因此,请保留一个可绘制的文件作为背景,如下所示:

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

You can use the following layout to achieve the required style : 您可以使用以下布局来实现所需的样式:

<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