[英]How to make a cardview layout with title stay on top of the borderline?
您可以使用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.