自定义属性错误 - 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
最满意答案
问题是,由于您正在使用
UITableViewController
,使用self.view.addSubview(toolbar)
,您已将工具栏添加为UITableViewController
视图的子view
,即UITableView
。 作为UITableView
的子视图,工具栏将与表一起滚动。解决方案:如果您想自定义视图控制器,请使用包含
UITableView
的UIView
而不是使用UITableViewController
。 这样,您可以向视图中添加不是tableview子视图的元素。The problem is that since you're using a
UITableViewController
, withself.view.addSubview(toolbar)
, you've added your toolbar as a subview of yourUITableViewController
'sview
, i.e. aUITableView
. As a subview of theUITableView
, the toolbar will scroll along with the table.The solution: Use a
UIView
containing aUITableView
instead of using aUITableViewController
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. ...
-
滚动时TableView重新排列/创建空白单元格。(TableView rearranging / creating blank cells when scrolling. Swift)[2022-07-14]
你应该这样做: 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 ...
-
Swift:tableView(Swift: tableView)[2023-05-16]
很难说出你正在尝试做什么,但你不应该在表视图数据源方法中使用任何异步方法。 这些方法应该只代表您已有的数据。 好像你只需用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 ...