簡體   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