RecyclerView 中的 CardView 有问题。
我的 CardView 突然变黑了,我的 RatingBar 变蓝了。我正在使用 InfiniteRecyclerView 但将其更改为简单的 RecyclerView 没有任何效果。我可以将 CardView 的背景颜色更改为白色,但 RatingBar 仍将是蓝色。这是正在发生的事情的一个例子:
我在具有相同适配器的 fragment 中的另一个 Activity 中使用普通的 RecyclerView,它看起来很好。这是一个例子:
这是 single_recipe_recycler_item.xml 布局文件:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="5dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:attr/selectableItemBackground"
android:orientation="horizontal">
<ImageView
android:id="@+id/recipe_recycler_image"
android:layout_width="80dp"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:src="@mipmap/ic_launcher" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="5dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="5dp">
<!-- RealmRecipe Title -->
<TextView
android:id="@+id/recipe_recycler_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:gravity="end"
android:text="Very very very very very very long title"
android:textColor="@color/colorBlack"
android:textSize="@dimen/title"
android:textStyle="bold" />
<!-- Publisher -->
<TextView
android:id="@+id/recipe_recycler_publisher"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_below="@id/recipe_recycler_title"
android:layout_marginTop="5dp"
android:text="Publisher"
android:textColor="@color/colorBlack"
android:textSize="@dimen/genre"
android:textStyle="italic" />
<!-- Rating -->
<RatingBar
android:id="@+id/recipe_recycler_rating_bar"
style="@style/Widget.AppCompat.RatingBar.Small"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_below="@id/recipe_recycler_publisher"
android:layout_marginTop="5dp"
android:isIndicator="true"
android:max="5" />
</RelativeLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
这是我的AppTheme:
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
为什么会这样? CardView 是否存在错误?有关如何解决此问题的任何建议?
最佳答案
我遇到了同样的问题,下面是我如何解决的。确保您的适配器按如下方式扩充布局。为了更好地理解,我们将此适配器称为 MyAdapter
@Override
public View getView(int position, View view, ViewGroup parent) {
if (view == null){
LayoutInflater layoutInflater = (LayoutInflater) getContext()
.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
view = layoutInflater.inflate(R.layout.recycler_row_layout_person, null, true);
}
然后,对于您将在其中使用适配器的Activity,请确保您使用的是正确的上下文。现在假设我们将在名为 MyActivity 的 Activity 中使用 MyAdapter。在错误上下文中使用布局充气器的错误方法如下
第一次走错
MyAdapter adapter = new MyAdapter(
getApplicationContext(), R.layout.recycler_row_layout_person, arrayList
);
第二种错误方式
MyAdapter adapter = new MyAdapter(
getContext(), R.layout.recycler_row_layout_person, arrayList
);
这是正确的方法。这就是我解决问题的方法。
MyAdapter adapter = new MyAdapter(
MyActivity.this, R.layout.recycler_row_layout_person, arrayList
);
希望对您有所帮助
关于android - CardView突然变黑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38185880/
最近因为项目需要,需要将Android手机系统自带的某个系统软件反编译并更改里面某个资源,并重新打包,签名生成新的自定义的apk,下面我来介绍一下我的实现过程。APK修改,分为以下几步:反编译解包,修改,重打包,修改签名等步骤。安卓apk修改准备工作1.系统配置好JavaJDK环境变量2.需要root权限的手机(针对系统自带apk,其他软件免root)3.Auto-Sign签名工具4.apktool工具安卓apk修改开始反编译本文拿Android系统里面的Settings.apk做demo,具体如何将apk获取出来在此就不过多介绍了,直接进入主题:按键win+R输入cmd,打开命令窗口,并将路
标题说明了一切。请注意,这不是模型或初始值设定项的更改。我可以删除Controller中的一个实例变量(例如,@user),然后重新加载一个View,它会工作-直到我重新启动服务器,在这种情况下它会提示变量为nil。我正常工作,然后切换到一组完全不同的Controller和View上工作,现在它无缘无故地发生了。应用处于开发环境中。development.rb内容:Dashboard::Application.configuredoconfig.cache_classes=falseconfig.whiny_nils=trueconfig.consider_all_requests_l
运行有问题或需要源码请点赞关注收藏后评论区留言一、利用ContentResolver读写联系人在实际开发中,普通App很少会开放数据接口给其他应用访问。内容组件能够派上用场的情况往往是App想要访问系统应用的通讯数据,比如查看联系人,短信,通话记录等等,以及对这些通讯数据及逆行增删改查。首先要给AndroidMaifest.xml中添加响应的权限配置 下面是往手机通讯录添加联系人信息的例子效果如下分成三个步骤先查出联系人的基本信息,然后查询联系人号码,再查询联系人邮箱代码 ContactAddActivity类packagecom.example.chapter07;importandroid
1.前言 在10.0的系统rom定制化开发中,在系统中有多个launcher的时候,会在开机进入launcher的时候弹窗launcher列表,让用户选择进入哪个launcher,这样显得特别的不方便所以产品开发中,要求用RoleManager的相关api来设置默认Launcher,但是在设置完默认Launcher以后,在安装一款Launcher的时候,默认Launcher就会失效,在系统设置的默认应用中Launcher选项就为空,点击home键的时候会弹出默认Launcher列表,让选择进入哪个默认Launcher.所以需要从安装Launcher的流程来分析相关的设置。来解决问题设置默认La
Ai-Bot基于流行的Node.js和JavaScript语言的一款新自动化框架,支持Windows和Android自动化。1、Windowsxpath元素定位算法支持支持Windows应用、.NET、WPF、Qt、Java和Electron客户端程序和ie、edgechrome浏览器2、Android支持原生APP和H5界面,元素定位速度是appium十倍,无线远程自动化操作多台安卓设备3、基于opencv图色算法,支持找图和多点找色,1080*2340全分辨率找图50MS以内4、内置免费OCR人工智能技术,无限制获取图片文字和找字功能。5、框架协议开源,除官方node.jsSDK外,用户可
前一段时间由于工作需要把可爱的小雪狐舍弃了,找到了小蜜蜂。但是新版本的小蜜蜂出现了很多和旧版本不一样的位置。1.功能位置迁移,原来在工程build.gradle的buildscript和allprojects移动至setting.gradle并改名为pluginManagement和dependencyResolutionManagement。里面的东西依旧可以按照原来的copy过来。pluginManagement{repositories{gradlePluginPortal()google()mavenCentral()}}dependencyResolutionManagement{r
关闭。这个问题不符合StackOverflowguidelines.它目前不接受答案。要求我们推荐或查找工具、库或最喜欢的场外资源的问题对于StackOverflow来说是偏离主题的,因为它们往往会吸引自以为是的答案和垃圾邮件。相反,describetheproblem以及迄今为止为解决该问题所做的工作。关闭9年前。Improvethisquestion我几乎用完了Ruby,但现在想试试Ruboto,android上的ruby。谷歌未能给我足够的(几乎没有结果)。所以任何人都可以分享一些关于Ruboto的教程。
Aproblemoccurredconfiguringrootproject'MyApplication2'.>Couldnotresolveallfilesforconfiguration':classpath'. >Couldnotresolvecom.android.tools.build:gradle:7.4.2. Requiredby: project:>com.android.application:com.android.application.gradle.plugin:7.4.2 project:>com.android.library:com.andr
简介:我们都知道在Android开发中,当我们的程序在与用户交互时,用户会得到一定的反馈,其中以对话框的形式的反馈还是比较常见的,接下来我们来介绍几种常见的对话框的基本使用。前置准备:(文章最后附有所有代码)我们首先先写一个简单的页面用于测试这几种Dialog(对话框)代码如下,比较简单,就不做解释了一、提示对话框(即最普通的对话框)首先我们给普通对话框的按钮设置一个点击事件,然后通过AlertDialog.Builder来构造一个对象,为什么不直接Dialog一个对象,是因为Dialog是一个基类,我们尽量要使用它的子类来进行实例化对象,在实例化对象的时候,需要将当前的上下文传过去,因为我这
问题描述:最近在写毕业论文,代码在ubuntu上跑的,得一边跑代码,一边写论文。但用一段时间,或者电脑静置一段时间后,键盘输入延迟突然变得很大,这期间鼠标是正常的,只是输不了字,得等几分钟才能恢复正常,非常耽误时间。解决方法后来参考下面这篇博客,说是ibus拼音输入法的问题,重启一下就行。ubuntuibus输入法突然无法输入(延迟过高)解决方法_q779的博客-CSDN博客_ubuntu键盘无法输入重启方法:终端输入"ibusrestart",键盘又可以正常使用了。ibusrestart自制脚本方法但是问题又来了,键盘有问题,输入延迟大,这样就没法在终端输入重启命令。因此我写了个脚本方式,每