简体   繁体   English

在CardView的顶部绘制标题栏

[英]Drawing A Title Bar At The Top Of A CardView

I am trying to draw a title bar on the top of a card view. 我正在尝试在卡片视图的顶部绘制标题栏。
This is what I am getting (Also why is the text "Test Title Goes Here" not being drawn? 这就是我得到的(为什么还没有画出“ Test Title Goes Here”?

https://imgur.com/cJqrzih

but I am looking for this 但是我在找这个

在此处输入图片说明

This is the xml I am using to get this 这是我正在使用的XML

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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">

    <android.support.v7.widget.CardView
        android:id="@+id/card"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:innerRadius="0dp"
        android:shape="ring"
        android:thicknessRatio="1.9"
        app:cardCornerRadius="40dp"
        app:contentPadding="13dp"
        tools:layout_editor_absoluteY="35dp">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">

            <TextView
                android:id="@+id/header_when"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="#D3D3D3"
                android:textColor="#000000"
                android:textStyle="bold"
                android:padding="8dp"
                tools:text="Test Title Goes Here" />

            <com.google.android.flexbox.FlexboxLayout
                android:id="@+id/layout"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                app:alignContent="stretch"
                app:alignItems="stretch"
                app:flexDirection="row"
                app:flexWrap="wrap"
                app:justifyContent="flex_start">

            </com.google.android.flexbox.FlexboxLayout>

        </LinearLayout>

    </android.support.v7.widget.CardView>

</android.support.constraint.ConstraintLayout>

Any help is greatly appreciated 任何帮助是极大的赞赏

Passing a xml for your textview should help you. 为textview传递xml应该会对您有所帮助。 Add the xml as background for the textview in your main xml layout. 在您的主要xml布局中,将xml添加为textview的背景。 In the custom textview xml do something like this:- 在自定义textview xml中执行以下操作:

<?xml version="1.0" encoding="UTF-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android"> 
    <solid android:color="#ffffffff"/>    

    <stroke android:width="3dp"
            android:color="#ff000000" />

    <padding android:left="1dp"
             android:top="1dp"
             android:right="1dp"
             android:bottom="1dp" /> 

    <corners android:bottomRightRadius="7dp"
             android:bottomLeftRadius="7dp"
             android:topLeftRadius="7dp"
             android:topRightRadius="7dp" /> 
</shape> 

I hope this helps. 我希望这有帮助。

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

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