使用XML将圆角添加到TextView的StateSelected Background(Add Rounded corners to StateSelected Background of TextView using XML)
我有
RecyclerView
,它包含一些TextView
。 我已将RecyclerView
背景设置为以下recycler_view_background.xml
。<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"> <solid android:color="#000000" /> <corners android:topLeftRadius="@dimen/player_category_radius" android:topRightRadius="@dimen/player_category_radius" android:bottomLeftRadius="@dimen/player_category_radius" android:bottomRightRadius="@dimen/player_category_radius"/> <stroke android:color="#D3D3D3" android:width="1dp" /> </shape>
它工作正常,我在
RecyclerView
上得到了圆角。这是一个问题,当我尝试将背景选择器添加到任何一个
TextViews
它们都没有显示圆角。 这是每个项目category_item_selector.xml
的背景xml
。<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_selected="true" android:drawable="@drawable/controlbar_gradient"> <shape> <corners android:topLeftRadius="@dimen/player_category_radius" android:topRightRadius="@dimen/player_category_radius" android:bottomLeftRadius="@dimen/player_category_radius" android:bottomRightRadius="@dimen/player_category_radius"/> <stroke android:color="#D3D3D3" android:width="1dp" /> </shape> </item> </selector>
我在我的
RecyclerView.Adapter.ViewHolder
的OnClickListener
以编程方式将TextView
的选择设置为true(选择器工作正常,否则我不会将所选项目带红色背景)。以下是该应用程序的片段。
RecyclerView
有圆角,但TextView
的背景正在绘制它。 因此,当所选View
位于顶部或底部时。圆角不再可见,即使在我在所选视图上添加圆角时也不应该看到。
我一直在寻找类似的解决方案。 根据这个 ,我的是正确的。
I have
RecyclerView
which holds someTextView
s. I have set background of theRecyclerView
to the followingrecycler_view_background.xml
.<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"> <solid android:color="#000000" /> <corners android:topLeftRadius="@dimen/player_category_radius" android:topRightRadius="@dimen/player_category_radius" android:bottomLeftRadius="@dimen/player_category_radius" android:bottomRightRadius="@dimen/player_category_radius"/> <stroke android:color="#D3D3D3" android:width="1dp" /> </shape>
And it works fine, I get rounded corners on my
RecyclerView
.Here's the catch, when I try to add a background selector to any one of the
TextViews
they don't show rounded corners. Here's the backgroundxml
for each itemcategory_item_selector.xml
.<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_selected="true" android:drawable="@drawable/controlbar_gradient"> <shape> <corners android:topLeftRadius="@dimen/player_category_radius" android:topRightRadius="@dimen/player_category_radius" android:bottomLeftRadius="@dimen/player_category_radius" android:bottomRightRadius="@dimen/player_category_radius"/> <stroke android:color="#D3D3D3" android:width="1dp" /> </shape> </item> </selector>
I am programmatically setting
TextView
's selected to true in myRecyclerView.Adapter.ViewHolder
'sOnClickListener
(Selector is working fine or else I wouldn't have reddish background to the selected item).Here are the snippets from the application.
RecyclerView
has rounded corners butTextView
's background is drawing over it. So when the selectedView
is on Top or Bottom.Rounded corners are no longer visible even though it shouldn't when I have added rounded corners on selected views.
I keep getting similar solutions when searching for this. And mine is correct according to this.
原文:https://stackoverflow.com/questions/35055683
最满意答案
我想在JavaScript中执行异步编程的最着名的库之一是caolan / async 。 (你可以通过GitHub上的明星数量看到它受欢迎的一个例子)
它被打包为npm模块,但代码也可以直接使用,并且根本不依赖于npm(顺便说一下,甚至不依赖于Node.js)。
您可以在GitHub上下载最新版本(master分支): https : //github.com/caolan/async/blob/master/lib/async.js
I guess one of the most famous libraries to perform asynchronous programming in JavaScript is caolan/async. (You can see one example of its popularity by the number of stars it has on GitHub)
It is packaged as an npm module, but the code is directly available too, and does not rely on npm at all (not even on Node.js by the way).
You can download the latest version (master branch) on GitHub there: https://github.com/caolan/async/blob/master/lib/async.js
相关问答
更多-
如果我是正确的,你试图更新你的package.json文件中的所有npm包? 我建议使用这个包。 安装包。 npm install grunt-auto-install --save-dev 将它添加到您的grunt任务中。 grunt.loadNpmTasks('grunt-auto-install'); 然后将配置添加到gruntfile.js grunt.initConfig({ auto_install: { local: {}, subdir: { option ...
-
如果要在全局安装npm模块,请确保使用新的-g标志,例如: npm install forever -g 关于从1.0rc开始的npm模块安装的一般建议(摘自blog.nodejs.org ): 如果您正在安装要在程序中使用的东西,请使用require('whatever'),然后在本地安装在项目的根目录。 如果要在shell中安装要使用的内容,请在命令行或其他内容中进行安装 ,以使其二进制文件最终在PATH环境变量中。 我刚刚使用这个建议,并且相当顺利地下降了。 我在全球安装了(因为它是一个命令行工具)和 ...
-
AVA只会传输您想运行的测试文件,而不是您要导入的模块。 但是你可以告诉AVA通过需要babel-register ( https://github.com/avajs/ava#transpiling-imported-modules )来传输导入的模块。 而且因为你已经配置了babel,你还可以告诉它使用你的配置。 将此添加到您的package.json "ava": { "babel": "inherit", "require": ["babel-register"] } 如果你想使用AVA使 ...
-
npm install将在NPM存储库中安装最新版本。 更改package.json的版本号后,可以运行npm publish将新版本发布到NPM。 npm install will install the latest version in the NPM repository. After changing the version number in your package.json, you can run npm publish to publish the new version to NPM. ...
-
我想在JavaScript中执行异步编程的最着名的库之一是caolan / async 。 (你可以通过GitHub上的明星数量看到它受欢迎的一个例子) 它被打包为npm模块,但代码也可以直接使用,并且根本不依赖于npm(顺便说一下,甚至不依赖于Node.js)。 您可以在GitHub上下载最新版本(master分支): https : //github.com/caolan/async/blob/master/lib/async.js I guess one of the most famous libr ...
-
嗨我用RC 6创建了Angular2延迟加载演示。 请查看https://github.com/Quramy/ng2-lazy-load-demo 。 Hi I've created Angular2 lazy loading demo using RC 6. Please checkout https://github.com/Quramy/ng2-lazy-load-demo .
-
Ng5 npm得到'无法找到模块'./topologicalSort''(Ng5 npm getting 'Cannot find module './topologicalSort'')[2023-01-23]
我会建议你完全删除node_modules目录,然后你应该从你的package.json删除这两个依赖关系 "css-loader": "0.28.11", "sass-loader": "7.0.0", 之后运行npm install ,然后再次运行它们: npm install sass-loader node-sass webpack --save-dev npm install --save-dev css-loader I will suggest you delete the node_m ... -
最简单的就是产生一个调用imagemagick程序的子进程。 否则,您可以扩展现有的Node映像模块以调用该C API。 Easiest is just spawn a child process that calls that imagemagick program. Otherwise you can extend an existing Node image module to call that C API.
-
您正在使用NVM安装的Node.js版本来运行npm link my-module-name ,但您没有使用相同版本运行npm link (在模块的目录中)。 初始链接在/usr/local/lib/node_modules ,但是当您使用NVM时,每个Node.js版本都会获得自己的“lib”目录,在您的示例/Users/XXX/.nvm/versions/node/v8.2.1/lib/node_modules ,这是一个不同的目录。 You're using an NVM-installed vers ...
-
可能最简单的方法是删除并重新安装node和npm。 有什么理由你不能这样做吗? 你有可能运行npm update -g吗? 这可能搞砸了,导致需要重新安装。 如果您只是想尝试重新安装npm ,并且您有一个工作node ,请使用以下脚本: curl -L https://www.npmjs.org/install.sh | SH Se https://github.com/npm/npm/wiki/Troubleshooting#if-your-npm-is-broken I just needed to a ...