首页 \ 问答 \ 使用XML将圆角添加到TextView的StateSelected Background(Add Rounded corners to StateSelected Background of TextView using XML)

使用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.ViewHolderOnClickListener以编程方式将TextView的选择设置为true(选择器工作正常,否则我不会将所选项目带红色背景)。

以下是该应用程序的片段。

在此处输入图像描述 在此处输入图像描述

RecyclerView有圆角,但TextView的背景正在绘制它。 因此,当所选View位于顶部或底部时。

圆角不再可见,即使在我在所选视图上添加圆角时也不应该看到。

我一直在寻找类似的解决方案。 根据这个 ,我的是正确的。


I have RecyclerView which holds some TextViews. I have set background of the RecyclerView to the following 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>

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 background xml for each item category_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 my RecyclerView.Adapter.ViewHolder's OnClickListener (Selector is working fine or else I wouldn't have reddish background to the selected item).

Here are the snippets from the application.

enter image description here enter image description here

RecyclerView has rounded corners but TextView's background is drawing over it. So when the selected View 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
更新时间:2022-06-29 08:06

最满意答案

我想在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 .
  • 我会建议你完全删除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 ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。