Xamarin没有看到我的自定义视图(Xamarin not seeing my custom view)
我有一个名为
SquareImageView
的自定义视图,我想在我的xml文件中使用它。 但我的xml似乎无法解决它。 为什么? 我试过给它一个小写的完全限定的命名空间XML:
<?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <pokemonmobileclient.SquareImageView android:id="@+id/picture" android:layout_width="match_parent" android:layout_height="match_parent" android:scaleType="centerCrop" /> <TextView android:id="@+id/text" android:layout_width="match_parent" android:layout_height="wrap_content" android:paddingLeft="10dp" android:paddingRight="10dp" android:paddingTop="15dp" android:paddingBottom="15dp" android:layout_gravity="bottom" android:textColor="@android:color/white" android:background="#55000000" /> </FrameLayout>
类:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using Android.App; using Android.Content; using Android.OS; using Android.Runtime; using Android.Text.Style; using Android.Util; using Android.Views; using Android.Widget; namespace PokemonMobileClient { public class SquareImageView : ImageView { public SquareImageView(IntPtr javaReference, JniHandleOwnership transfer) : base(javaReference, transfer) { } public SquareImageView(Context context) : base(context) { } public SquareImageView(Context context, IAttributeSet attrs) : base(context, attrs) { } public SquareImageView(Context context, IAttributeSet attrs, int defStyleAttr) : base(context, attrs, defStyleAttr) { } public SquareImageView(Context context, IAttributeSet attrs, int defStyleAttr, int defStyleRes) : base(context, attrs, defStyleAttr, defStyleRes) { } protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec) { base.OnMeasure(widthMeasureSpec, heightMeasureSpec); SetMeasuredDimension(this.MeasuredWidth, this.MeasuredHeight); } } }
<pokemonmobileclient.SquareImageView
有一个下划线表示invalid child element pokemonmobileclient.SquareImageView
为什么我不能参考呢?
谢谢
I have a custom view called
SquareImageView
which I want to use in my xml file. But my xml can't seem to resolve it. Why? I've tried giving it the fully qualified namespace in lowercasexml:
<?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <pokemonmobileclient.SquareImageView android:id="@+id/picture" android:layout_width="match_parent" android:layout_height="match_parent" android:scaleType="centerCrop" /> <TextView android:id="@+id/text" android:layout_width="match_parent" android:layout_height="wrap_content" android:paddingLeft="10dp" android:paddingRight="10dp" android:paddingTop="15dp" android:paddingBottom="15dp" android:layout_gravity="bottom" android:textColor="@android:color/white" android:background="#55000000" /> </FrameLayout>
Class:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using Android.App; using Android.Content; using Android.OS; using Android.Runtime; using Android.Text.Style; using Android.Util; using Android.Views; using Android.Widget; namespace PokemonMobileClient { public class SquareImageView : ImageView { public SquareImageView(IntPtr javaReference, JniHandleOwnership transfer) : base(javaReference, transfer) { } public SquareImageView(Context context) : base(context) { } public SquareImageView(Context context, IAttributeSet attrs) : base(context, attrs) { } public SquareImageView(Context context, IAttributeSet attrs, int defStyleAttr) : base(context, attrs, defStyleAttr) { } public SquareImageView(Context context, IAttributeSet attrs, int defStyleAttr, int defStyleRes) : base(context, attrs, defStyleAttr, defStyleRes) { } protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec) { base.OnMeasure(widthMeasureSpec, heightMeasureSpec); SetMeasuredDimension(this.MeasuredWidth, this.MeasuredHeight); } } }
<pokemonmobileclient.SquareImageView
has an underline sayinginvalid child element pokemonmobileclient.SquareImageView
Why can't I reference it?
Thanks
原文:https://stackoverflow.com/questions/38908036
最满意答案
持久Realm对象只能在读取它们的同一个线程上读取或写入。 假设
[self downloadMedia:success:failure:]
的成功块是在与读取的messages
不同的线程上调用的,这意味着您无法在块中使用message
。 为当前线程创建新的RLMRealm
实例对捕获的变量没有任何影响。Persisted Realm objects can only be read from or written to on the same thread as they were fetched on. Assuming that the success block for
[self downloadMedia:success:failure:]
is being called on a different thread thanmessages
was read on, this means that you can't usemessage
within the block. Creating a newRLMRealm
instance for the current thread does not have any effect on the captured variables.
相关问答
更多-
您只能在事务中操作Realm对象,或者只能在读/写这些对象的线程中操作。 在您的情况下,您从readData方法获取RealmResult并使用RxJava切换导致异常的线程。 使用copyFromRealm从realm获取数据,它将它们作为普通对象而不是realm对象返回。 You can only manipulate Realm objects in a transaction or only in the thread you read/write these objects. In your ca ...
-
我不熟悉Realm,但似乎你可能不得不从主线程调用它? 尝试打印出日志中的当前线程(Thread.current),看看你是否在后台运行。 如果是这种情况,请在DispatchQueue.main.async(执行:{})中包装您的执行/添加调用,以查看是否可以解决问题? I'm not familiar with Realm but it appears that you may have to call it from the main thread? Try printing out the curr ...
-
从文档: RLMRealm实例不是线程安全的,不能跨线程或调度队列共享。 您必须在要与领域交互的每个线程上调用此方法。 对于调度队列,这意味着您必须在每个调度的块中调用它,因为不保证队列在一致的线程上运行 From the documentation: RLMRealm instances are not thread safe and can not be shared across threads or dispatch queues. You must call this method on each ...
-
我发现了如何解决它。 要将服务器响应从改造2保存到领域,然后传递给UI。 我通过覆盖Gson Builder来改造返回领域对象,如下所示: Retrofit.Builder() .baseUrl(RestApi.API_BASE_URL) .client(okHttpClient) .callbackExecutor(new JobExecutor()) .addConverterFactory(GsonConv ...
-
持久Realm对象只能在读取它们的同一个线程上读取或写入。 假设[self downloadMedia:success:failure:]的成功块是在与读取的messages不同的线程上调用的,这意味着您无法在块中使用message 。 为当前线程创建新的RLMRealm实例对捕获的变量没有任何影响。 Persisted Realm objects can only be read from or written to on the same thread as they were fetched on. ...
-
似乎写入发生在与最初访问对象不同的线程上。 您应该能够通过传递task的id来修复它,并在执行写入之前使用它来从数据库中获取它(在异步块内)。 所以在顶部: var taskId = 0 // Set this accordingly 然后像 self.queue.async { autoreleasepool { let realm = try! Realm() let tempTask = // get task from Realm based on tas ...
-
下载完成Swift 3后,从错误的线程访问域(Realm accessed from incorrect thread after download completed Swift 3)[2023-08-09]
尝试在validate块中创建另一个域线程对象 .validate { request, response, temporaryURL, destinationURL in self.localPath = destinationURL magazineObject.pathDatabase = String(describing: self.localPath!) magazineObject.progressBarDownload = Double(self.percentPro ... -
假设您正在从主线程调用显示的代码片段,例如从视图控制器中调用,您可能在另一个线程上使用主线程中的RLMRealm实例。 let priority = DISPATCH_QUEUE_PRIORITY_DEFAULT dispatch_async(dispatch_get_global_queue(priority, 0)) { // Get a Realm for the current thread RLMRealm *realm = [RL ...
-
你使用单例设置的方式只有1个Realm实例。 如果你调用realmProcessor.getRealm(); 在线程A中,然后在线程B中再次调用它们,它们返回相同的实例。 Realm不允许在线程之间共享实例。 由于AsyncTask的doInBackground在单独的线程上运行,因此这不起作用。 更改为此将消除错误。 但是你有一些重新设计要做。 @Override protected Boolean doInBackground(Void... params) { Realm realmObj = ...
-
告诉你是否是在线程上执行的唯一一个简单而肮脏的方法将依赖于无人看守的静态变量: -(void)concurrentMethod { static NSThread *runningThread = nil; NSThread *myThread = [NSThread currentThread]; if (runningThread != nil) { NSLog(@"Thread %@: running concurrently with %@", running ...