简体   繁体   中英

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

you can use fieldset to achive that goal.

<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. Inside an item you can use new Chip view (see 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. 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"/>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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