【问题标题】:how to add a box over card view on selection?如何在选择时在卡片视图上添加一个框?
【发布时间】:2015-10-25 09:00:09
【问题描述】:

我有一个使用卡片视图和回收器视图创建的小时列表。我想展示一些时间选择的变化。在选择时我想在图像中显示蓝色框的类型。我怎样才能实现它? 我想我需要在父布局中添加多个布局并更改布局的背景颜色。方法对吗??或者有没有其他办法???

卡片布局

    <?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>

请帮忙...

【问题讨论】:

    标签: java android list layout


    【解决方案1】:

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

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

    在这种情况下,您需要为您的视图设置所有叠加参数,然后在画布上绘制一个选择。这是关于它的good article

    【讨论】:

      猜你喜欢
      • 2020-12-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多