标签: android-cardview

Android:如何在CardView中插入RecyclerView?

我说的活动必须展现出RecyclerView通过填充CardViews作为项目.我的目标是在每个CardView中显示一个RecyclerView.

这是我的Activity的基本xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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=".ConjActivity" >

    <android.support.v7.widget.RecyclerView
        android:id="@+id/conjCardList"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:clickable="false" />

</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

这是我的CardView的RecyclerView的布局:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/card_analysis"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="@dimen/activity_vertical_margin"
    android:layout_marginBottom="@dimen/activity_vertical_margin" 
    android:layout_marginLeft="@dimen/activity_horizontal_margin"
    android:layout_marginRight="@dimen/activity_horizontal_margin"
    android:padding="5dp"
    card_view:cardCornerRadius="5dp" >

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

        <android.support.v7.widget.RecyclerView
            android:id="@+id/item_mode"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:paddingTop="5dp"
            android:paddingLeft="@dimen/activity_horizontal_margin" >

        </android.support.v7.widget.RecyclerView>
    </LinearLayout>
</android.support.v7.widget.CardView>
Run Code Online (Sandbox Code Playgroud)

所以,我大胆地通过实现两个RecyclerView.Adapters来实现我的第一次尝试,一个用于(让我们称之为)"主"RecyclerView,一个用于每个CardView中的单个:

以下是两段代码:

"Main"RecyclerView(带ViewHolders):

public class ConjCardAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>{

    private static Context context;
    private LinearLayoutManager llm;
    private static ConjFormAdapter formAdapt;
    private ArrayList<String> adapterList;
    private …
Run Code Online (Sandbox Code Playgroud)

android android-viewholder android-cardview recycler-adapter android-recyclerview

15
推荐指数
2
解决办法
2万
查看次数

如何在cardview前面引入imageView?当两者都是相对布局的孩子

我有一个布局XML:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/containor"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#fff6da"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.vats.vatishs.cardviewprogrammatically.MainActivity">

        <FrameLayout
            android:id="@+id/card"
            android:layout_width="220dp"
            android:layout_marginTop="10dp"
            android:layout_height="wrap_content">

            <TextView
                android:background="@color/white"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:padding="10dp"
                android:text="Hello I am a text View." />

        </FrameLayout>

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="210dp"
        android:background="@drawable/select_delete_chim" />

</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

哪个工作正常.结果将是框架布局上方的图像视图,但是当我使用下面的xml时,我用CardView替换了框架布局:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/containor"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#fff6da"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.vats.vatishs.cardviewprogrammatically.MainActivity">

        <android.support.v7.widget.CardView
            android:id="@+id/card"
            android:layout_width="220dp"
            android:layout_marginTop="10dp"
            android:layout_height="wrap_content">

            <TextView
                android:background="@color/white"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:padding="10dp"
                android:text="Hello I am a text View." />

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

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="210dp"
        android:background="@drawable/select_delete_chim" …
Run Code Online (Sandbox Code Playgroud)

android android-cardview android-elevation

15
推荐指数
2
解决办法
1万
查看次数

单击recyclerview时,父级单击事件不会触发

我有一个带有几个TextView的CardView中的RecyclerView.CardView有一个OnClickListener集合,在单击TextViews时会被触发,但在单击RecyclerView时不会触发.

这是CardView的样子:

<?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="match_parent"
    android:layout_margin="5dp"
    card_view:cardCornerRadius="4dp"
    card_view:cardElevation="5dp">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:weightSum="100"
        android:minWidth="100dp">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:id="@+id/text1"
            android:textColor="@color/abc_primary_text_material_light"
            android:layout_weight="1"
            android:layout_gravity="center_horizontal" />

        <android.support.v7.widget.RecyclerView
            android:id="@+id/recyclerView"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:listSelector="@color/highlighted_text_material_light"
            android:layout_weight="98" />

        <View
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:background="@android:color/black" />

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/relativeSummary"
            android:orientation="horizontal"
            android:layout_weight="1">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceLarge"
                android:id="@+id/text2"
                android:textAlignment="viewEnd"
                android:textColor="@color/abc_secondary_text_material_light"
                android:layout_marginLeft="5dp"
                android:layout_marginRight="5dp"
                android:gravity="start"
                android:singleLine="true"
                android:layout_alignParentLeft="true" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceLarge"
                android:id="@+id/text3"
                android:textColor="@color/abc_primary_text_material_light"
                android:layout_marginRight="5dp"
                android:layout_marginLeft="5dp"
                android:gravity="end"
                android:singleLine="true"
                android:layout_alignParentRight="true"
                android:layout_toRightOf="@+id/text2" />

        </RelativeLayout>
    </LinearLayout>
</android.support.v7.widget.CardView>
Run Code Online (Sandbox Code Playgroud)

我不需要在这个RecyclerView上有一个点击监听器,而且当单击RecyclerView时,实际上只需要触发父视图的click事件(OnLongClick事件也是如此).我还需要RecyclerView来滚动.RecyclerView是一些如何吃点击事件而不是将其传递给父母的?

android android-cardview android-recyclerview

14
推荐指数
3
解决办法
6572
查看次数

在android中创建关于cardview的视图

我想创建这个布局
在此输入图像描述

这是我使用此代码的cardview(灰色视图)和imageview(蓝色视图)

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/abc_search_url_text_normal"
android:orientation="vertical">

<android.support.v7.widget.CardView
    android:layout_width="match_parent"
    android:layout_height="100dp"
    android:layout_alignParentBottom="true"
    android:layout_gravity="bottom"
    android:layout_marginBottom="3dp"
    android:paddingTop="5dp"
    app:cardBackgroundColor="@color/abc_input_method_navigation_guard">


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

<ImageView
    android:layout_width="100dp"
    android:layout_height="100dp"
    android:layout_gravity="bottom"
    android:layout_marginBottom="30dp"
    android:layout_marginRight="10dp"
    android:scaleType="fitXY"
    android:src="@drawable/abc_ratingbar_full_material" />

</FrameLayout>
Run Code Online (Sandbox Code Playgroud)

但结果我的图像视图回到了cardview,我尝试了reletivelayout而不是framelayout,但结果相同.

xml android android-layout android-cardview

14
推荐指数
4
解决办法
9184
查看次数

将CardView添加到布局时出错

我想试试谷歌给我们的新玩具,我遇到了一些麻烦.

这是我的build.gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 'android-L'
    buildToolsVersion "20.0.0"

    defaultConfig {
        applicationId "com.tod.android.lpreviewtest"
        minSdkVersion 'L'
        targetSdkVersion 'L'
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:cardview-v7:+'
}
Run Code Online (Sandbox Code Playgroud)

现在我的布局:

<RelativeLayout 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"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    tools:context=".MyActivity">
    <android.support.v7.widget.CardView
        xmlns:card_view="http://schemas.android.com/apk/res-auto"
        android:id="@+id/card_view"
        android:layout_gravity="center"
        android:layout_width="200dp"
        android:layout_height="200dp"
        card_view:cardCornerRadius="4dp">

        <TextView
            android:id="@+id/info_text"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
    </android.support.v7.widget.CardView>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

当我在android studio中切换到屏幕预览时,我收到渲染错误:

Rendering Problems The following classes could not …
Run Code Online (Sandbox Code Playgroud)

xml android android-cardview

13
推荐指数
4
解决办法
3万
查看次数

如何展开CardView以显示Google Keep卡等更多详细信息?

我的应用程序中有一些CardView,我希望它们像Google Keep中的卡一样运行.例如,当我单击具有文本的卡片时,它会(使用动画)扩展到另一个视图中.

如果您不确定我的意思,请在Google Keep Android应用上创建一个备注,点按创建备忘时显示的卡片.这正是我想在我的应用程序中发生的事情.

我该怎么做呢?

android android-animation android-cardview

13
推荐指数
1
解决办法
2万
查看次数

RecyclerView与不同的Cardlayouts

我想做什么


此刻,我正在RecyclerView和我一起玩CardView.现在我写了一个RecyclerView.Adapter,我可以用不同的内容多次显示相同的CardView - 类似于ListViewa BaseAdapter.

现在我想写一个RecyclerView不同CardView-Layout的(以Google Now的风格).我已经搜索了教程,但没有发现有关该主题的任何有用信息.有人知道,这需要如何实施?要意识到这一点需要做些什么?

android android-cardview recycler-adapter android-recyclerview

13
推荐指数
1
解决办法
9018
查看次数

带有CardView的Android RecyclerView - 以堆栈形式显示卡片(不是列表)

我想使用RecyclerViewAndroid支持v7库中的那个来显示一堆CardViews(也在v7支持库中),但不是在列表中显示它们(我可以向上/向下滚动)我想要将它们显示为堆栈(如卡堆栈).

有谁知道我怎么能实现这种行为?

谢谢!!

android material-design android-cardview android-recyclerview

13
推荐指数
1
解决办法
1532
查看次数

CardView:如何在保持半径的同时添加渐变背景

我想用 CardView 重新创建下面的图像。为此,我创建了一个渐变文件 (btn_gradient.xml),然后继续创建 CardView。

在此处输入图片说明

CardView 实现:

<android.support.v7.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="44dp"
        android:layout_margin="25dp"
        app:cardElevation="0dp"
        app:cardCornerRadius="4dp"
        app:cardPreventCornerOverlap="false">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center"
            android:background="@drawable/btn_gradient"
            android:text="Create Account"
            android:textColor="#000000"
            android:textStyle="bold"
            android:textAllCaps="false"/>


    </android.support.v7.widget.CardView>
Run Code Online (Sandbox Code Playgroud)

除了半径消失而且这不是我想要的之外,一切都以这种方式正常工作。有没有办法可以直接在 CardView 上设置渐变?该cardBackgroundColor属性仅接受颜色,不接受可绘制对象。

任何帮助,将不胜感激。



附录:
根据要求,这是我的 btn_gradient.xml 文件:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
    android:type="linear"
    android:angle="0"
    android:startColor="#ffc200"
    android:endColor="#fca10b" />
</shape>
Run Code Online (Sandbox Code Playgroud)

xml android android-cardview

13
推荐指数
2
解决办法
1万
查看次数

在CardView中展开/折叠动画

我尝试做这样的事情: 在此输入图像描述

我设法做了我的cardViewAdapter,但我阻止扩大我的卡.我恢复了这个响应的代码(这里的类名是CardsAnimationHelper:)来做动画,但它是叠加的.

在扩展之前: 图片 扩展后: 图片

我解决了上面的问题,但如果在我的cardView上我同时显示10个元素的50个列表.如果我扩展第一个,数字11,21,31,41也将扩展.你有诀窍吗?

我反思过,这对我来说毫无意义.就在我的OnClick方法之前,我显示了一个textview,其中文本是位置.但是当我点击id是正确的,这意味着当我点击它时会检测到几张牌上的点击.我想我的OnClickListener中的视图可能有问题

我的CardView

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

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="5dp"

        app:cardBackgroundColor="@android:color/white"
        app:cardCornerRadius="2dp"
        app:cardElevation="2dp">

        <!-- Les CardView possèdent des attributs supplémentaires dont
             - cardBackgroundColor
             - cardElevation pour l'élévation (donc aussi l'ombre)
             - cardCornerRadius pour arrondir les angles
         -->

        <android.support.design.widget.CoordinatorLayout 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">

            <!-- Les CardView agissent comme des FrameLayout,
             pour avoir une organisation verticale nous devons
             donc rajouter un LinearLayout -->


            <TextView
                android:id="@+id/text_cards" …
Run Code Online (Sandbox Code Playgroud)

android android-layout android-cardview

12
推荐指数
2
解决办法
2万
查看次数