首页 \ 问答 \ 自定义属性错误 - Android Studio 1.2(Custom Attribute Error - Android Studio 1.2)

自定义属性错误 - Android Studio 1.2(Custom Attribute Error - Android Studio 1.2)

在我的Android项目中,我有几个使用自定义属性的自定义组件。

attrs.xml文件如下所示:

<?xml version="1.0" encoding="utf-8"?>
<resources >
    <declare-styleable name = "TextBox">
        <attr name = "font" format = "string"/>
    </declare-styleable>

    <declare-styleable name = "ButtonBox">
        <attr name = "font" format = "string"/>
    </declare-styleable>
</resources>

我在自定义组件中提取属性很好,但是当我去运行代码时,我看到以下错误。

错误:找到项目Attr / font多次
错误:任务':app:mergeDebugResources'的执行失败。

在两个不同的declare-styleable资源中有类似的属性名称是否正确应该没有区别?

如果您有任何帮助,将不胜感激,谢谢!


In my Android project I have a couple of custom components that use custom attributes.

The attrs.xml file looks like this:

<?xml version="1.0" encoding="utf-8"?>
<resources >
    <declare-styleable name = "TextBox">
        <attr name = "font" format = "string"/>
    </declare-styleable>

    <declare-styleable name = "ButtonBox">
        <attr name = "font" format = "string"/>
    </declare-styleable>
</resources>

I am pulling in the attributes just fine in the custom component, but when I go to run the code I see the following error.

Error: Found item Attr/font more than one time
Error: Execution failed for task ':app:mergeDebugResources'.

It shouldn't make a difference that there are similar attribute names in two different declare-styleable resources correct?

If you have any help it would be greatly appreciated, thank you!


原文:https://stackoverflow.com/questions/30038982
更新时间:2023-08-06 17:08

最满意答案

问题是,由于您正在使用UITableViewController ,使用self.view.addSubview(toolbar) ,您已将工具栏添加为UITableViewController视图的子view ,即UITableView 。 作为UITableView的子视图,工具栏将与表一起滚动。

解决方案:如果您想自定义视图控制器,请使用包含UITableViewUIView而不是使用UITableViewController 。 这样,您可以向视图中添加不是tableview子视图的元素。


The problem is that since you're using a UITableViewController, with self.view.addSubview(toolbar), you've added your toolbar as a subview of your UITableViewController's view, i.e. a UITableView. As a subview of the UITableView, the toolbar will scroll along with the table.

The solution: Use a UIView containing a UITableView instead of using a UITableViewController if you'd like to customize your view controller. That way you can add elements to the view that aren't subviews of your tableview.

相关问答

更多
  • UITableView继承自UIScrollView , UITableView继承UIScrollViewDelegate 。 特别是您可能对scrollViewDidScroll方法感兴趣。 所以,在你的UITableViewDelegate实现中,添加下面的方法: func scrollViewDidScroll(_ scrollView: UIScrollView) { NSLog("Table view scroll detected at offset: %f", scrollView. ...
  • 你应该这样做: public func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return Int(numberofContacts) } public func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { ...
  • 发生这种情况是因为它是在滚动视图中具有表视图的行为。 应该发生这种情况。 解决方案:销毁scrollView,并使用标题视图实现tableView,希望标题视图将是带有uiimage,webview等的视图...而tableView它将是您的评论。 这是实现你想要的最佳方式,也就是说,如果我理解你真正想要的东西。 将标头添加到表视图示例: self.tableView.tableHeaderView = topView // where top view is the view wish contains ...
  • 很难说出你正在尝试做什么,但你不应该在表视图数据源方法中使用任何异步方法。 这些方法应该只代表您已有的数据。 好像你只需用cell.textLabel?.text = "\(classes[indexPath.row].section!)"替换整个getTime块cell.textLabel?.text = "\(classes[indexPath.row].section!)" 。 It's hard to tell what you're trying to do exactly, but you sh ...
  • 你应该更新单元格的字段。 也许你在这里UITableViewCell重用好的做法可以帮到你 you should update field of the cell. maybe you here UITableViewCell reuse good practice can help you
  • 尝试使用符合UITableViewDelegate和UITableViewDataSource的普通UIViewController,而不是使用UITableViewController。 将UITableView作为子视图添加到视图控制器的主视图,并将其委托和数据源链接到视图控制器。 现在,您可以将任何其他UIViews添加到主视图,该主视图将固定在UITableView的顶部。 Instead of using a UITableViewController try using a plain UIVi ...
  • NSData(contentsOf: (imgURL as URL?)!)是同步的。 请参阅SDK文档: https : //developer.apple.com/reference/foundation/nsdata/1547245-datawithcontentsofurl 其中说明: Do not use this synchronous method to request network-based URLs. For network-based URLs, this method can blo ...
  • 你可以使用属性scrollEnabled并将其设置为false 。 例如: tableView.scrollEnabled = false; U can use the property scrollEnabled and set it to false. For Example: tableView.scrollEnabled = false;
  • 问题是,由于您正在使用UITableViewController ,使用self.view.addSubview(toolbar) ,您已将工具栏添加为UITableViewController视图的子view ,即UITableView 。 作为UITableView的子视图,工具栏将与表一起滚动。 解决方案:如果您想自定义视图控制器,请使用包含UITableView的UIView而不是使用UITableViewController 。 这样,您可以向视图中添加不是tableview子视图的元素。 The ...
  • 另一个选择是将其设置为具有两个部分的单个集合视图,一个看起来并作为tableview进行布局,另一个具有更多集合视图外观。 或者将它设置为具有两个部分的单个表格视图,其中一个部分每行显示两个并排图像(这是创建此布局的老派方式)。 有很多方法可以解决,取决于你想玩什么以及你想学习什么:) Another option is to set it up as a single collection view with two sections, one that looks and lays out as a t ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)