繁体   English   中英

如何在选择时在卡片视图上方添加一个框?

[英]how to add a box over card view on selection?

我有一个使用卡视图和回收者视图创建的小时数列表。 我想显示某些小时的变化。 选择后,我想在图像中显示蓝色框的类型。 我该如何实现? 我想我需要在父布局中添加多个布局,并更改布局的背景颜色。 这是正确的方法吗? 还是有其他可能的方式???

在此处输入图片说明

卡布局

    <?xml version="1.0" encoding="utf-8"?>

    <android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:card_view="http://schemas.android.com/apk/res-auto"
        android:id="@+id/card_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@android:color/holo_blue_light">

<RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="60dp"
            android:id="@+id/relativeLayout"
            android:layout_alignParentTop="true">

    <ImageView
                android:layout_width="280dp"
                android:layout_height="2dp"
                android:id="@+id/imageView"
                android:background="@drawable/lineh"
        android:layout_marginRight="20dp"
        android:layout_centerVertical="true"
        android:layout_alignParentEnd="true" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:text="Small Text"
        android:id="@+id/txthour"
        android:layout_marginLeft="10dp"
        android:layout_centerVertical="true"
       />
</RelativeLayout>
</android.support.v7.widget.CardView>

主要布局

    <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/nav_drawer"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:id = "@+id/toolbar_container">

        <android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:app="http://schemas.android.com/apk/res-auto"
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"/>

        <FrameLayout
            android:id="@+id/nav_contentframe"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@android:color/background_light"
            android:layout_below="@+id/toolbar">
            </FrameLayout>

    </LinearLayout>

    <android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:fitsSystemWindows="true"
        app:headerLayout="@layout/drawer_header"
        app:menu="@menu/nav_menu"
        android:background="@android:color/background_light" />

</android.support.v4.widget.DrawerLayout>

片段布局

  <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
    android:layout_height="match_parent" tools:context="com.example.siddhi.timetablelayout.List"
    android:background="@android:color/holo_blue_bright">

    <android.support.v7.widget.RecyclerView
        android:layout_height="match_parent"
        android:layout_width="match_parent"
        android:id="@+id/RecyclerView"
        android:background="@android:color/white"
        android:layout_weight="1.40"
        android:layout_gravity="right|bottom" />


</FrameLayout>

请帮忙...

我建议您为此使用自定义视图(或显然是布局)。 您需要做的是重写onDraw方法:

@Override
public void onDraw(Canvas canvas){
    super.onDraw(canvas);
    drawOverlay(canvas);
}

在这种情况下,您需要为视图设置所有叠加参数,然后在画布上进行选择。 这是一篇很好的文章

暂无
暂无

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

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