当我使用RecyclerVIEw在我的应用程序中显示列表数据时,RecyclerVIEw的backgroundcolor始终为白色:
我在xml文件和代码中设置backgroundcolor,但它不起作用:
//activity_main.xml<?xml version="1.0" enCoding="utf-8"?><linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID" androID:layout_wIDth="match_parent" androID:layout_height="match_parent" androID:fitsSystemwindows="true" androID:orIEntation="vertical" androID:background="@color/colorPrimary"> <!--<include layout="@layout/content_main" />--> <FrameLayout androID:ID="@+ID/fragment_container" androID:layout_wIDth="match_parent" androID:layout_height="match_parent"></FrameLayout></linearLayout>//fragment_layout.xml<?xml version="1.0" enCoding="utf-8"?><relativeLayout xmlns:androID="http://schemas.androID.com/apk/res/androID" androID:layout_wIDth="match_parent" androID:layout_height="match_parent" androID:background="@color/colorAccent"> <androID.support.v7.Widget.RecyclerVIEw androID:ID="@+ID/List_vIEw" androID:layout_wIDth="match_parent" androID:layout_height="wrap_content" androID:background="@color/colorAccent" androID:padding="5dp" /></relativeLayout>//item_layout.xml<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:layout_wIDth="match_parent" androID:layout_height="wrap_content" androID:layout_@R_502_5553@="5dp" card_vIEw:cardBackgroundcolor="@color/yellow" card_vIEw:cardCornerRadius="1dp"> <relativeLayout androID:layout_wIDth="match_parent" androID:layout_height="wrap_content" androID:padding="5dp"> <TextVIEw androID:ID="@+ID/name" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:layout_centerHorizontal="true" androID:layout_@R_502_5553@Bottom="5dip" androID:layout_@R_502_5553@top="5dip" androID:gravity="center" androID:textcolor="@color/text_white" androID:textSize="@dimen/List_item_text_size" /> <ImageVIEw androID:ID="@+ID/pic" androID:layout_wIDth="match_parent" androID:layout_height="wrap_content" androID:layout_below="@+ID/name" androID:scaleType="centerCrop" /> </relativeLayout></androID.support.v7.Widget.CardVIEw> //gradle file compileSdkVersion 23 buildToolsversion "23.0.2" defaultConfig { applicationID "com.union.fmdouban" minSdkVersion 15 targetSdkVersion 23 versionCode 1 versionname "1.0" }
解决方法:
我已经实现了以下代码,这显示了卡片视图和背景color
<?xml version="1.0" enCoding="utf-8"?><relativeLayout xmlns:androID="http://schemas.androID.com/apk/res/androID" androID:layout_wIDth="match_parent" androID:layout_height="match_parent"> <androID.support.v7.Widget.RecyclerVIEw androID:ID="@+ID/appointment_List" androID:layout_wIDth="match_parent" androID:layout_height="match_parent" androID:background="#FFFF00" androID:scrollindicators="none" /></relativeLayout>
//你的适配器的布局
<androID.support.v7.Widget.CardVIEw xmlns:androID="http://schemas.androID.com/apk/res/androID" androID:ID="@+ID/card_vIEw" androID:layout_wIDth="match_parent" androID:layout_height="wrap_content" androID:layout_@R_502_5553@="10dp"> <relativeLayout androID:layout_wIDth="match_parent" androID:layout_height="wrap_content" androID:background="#000" androID:padding="5dp"> <TextVIEw androID:ID="@+ID/name" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:layout_centerHorizontal="true" androID:layout_@R_502_5553@Bottom="5dip" androID:layout_@R_502_5553@top="5dip" androID:gravity="center" androID:text="dfgjkdfh" androID:textcolor="#ffffff" /> <ImageVIEw androID:ID="@+ID/pic" androID:layout_wIDth="match_parent" androID:layout_height="wrap_content" androID:layout_below="@+ID/name" androID:scaleType="centerCrop" /> </relativeLayout></androID.support.v7.Widget.CardVIEw>
我从适配器的XML中删除了主要的相对布局试试这个让我知道
//我的Gradle看起来像这样
apply plugin: 'com.androID.application'androID { compileSdkVersion 23 buildToolsversion "23.0.2" defaultConfig { applicationID "betasoft.com.tryso" minSdkVersion 15 targetSdkVersion 23 versionCode 1 versionname "1.0" } buildTypes { release { MinifyEnabled false proguardfiles getDefaultProguardfile('proguard-androID.txt'), 'proguard-rules.pro' } }}dependencIEs { compile filetree(dir: 'libs', include: ['*.jar']) compile 'com.androID.support:appcompat-v7:23.1.1' compile 'com.androID.support:cardvIEw-v7:23.1.0' compile 'com.androID.support:design:23.1.1' }
总结 以上是内存溢出为你收集整理的android RecyclerView BackgroundColor全部内容,希望文章能够帮你解决android RecyclerView BackgroundColor所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)