[英]TextureView doesn't support displaying a background drawable Xamarin Android
i have a problem with TextureView when i do inflate operation for camera2 implementation. 我为camera2实现执行充气操作时,TextureView出现问题。
i have the problem with Android 8 but it is work with samsung s5 Android 6. 我在Android 8上遇到问题,但在三星s5 Android 6上可以使用。
Error: 错误:
{Android.Views.InflateException: Binary XML file line #1: Error
inflating class md5773532591b176ca6c4550eebd08312bd.AutoFitTextureView
---> Java.Lang.Reflect.InvocationTargetException: Exception of type
'Java.Lang.Reflect.InvocationTargetException' was thrown. --->
Java.Lang.UnsupportedOperationException: TextureView doesn't support
displaying a background drawable
--- End of inner exception stack trace ---
--- End of inner exception stack trace ---
--- End of managed Android.Views.InflateException stack trace ---
android.view.InflateException: Binary XML file line #1: Error inflating
class md5773532591b176ca6c4550eebd08312bd.AutoFitTextureView
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:334)
at android.view.LayoutInflater.createView(LayoutInflater.java:658)
at
android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:801)
at
android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:741)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:874)
at
android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:835)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:877)
at
android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:835)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at Camera2BasicFragment.n_onCreateView(Native Method)
at Camera2BasicFragment.onCreateView(Camera2BasicFragment.java:44)
at android.app.Fragment.performCreateView(Fragment.java:2626)
at
android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1279)
at
android.app.FragmentManagerImpl.addAddedFragments
(FragmentManager.java:2422)
at android.app.FragmentManagerImpl.executeOpsTogether
(FragmentManager.java:2201)
at
android.app.FragmentManagerImpl.removeRedundantOperationsAndExecute
(FragmentManager.java:2155)
at android.app.FragmentManagerImpl.execPendingActions
(FragmentManager.java:2056)
at android.app.FragmentManagerImpl$1.run(FragmentManager.java:719)
at android.os.Handler.handleCallback(Handler.java:808)
at android.os.Handler.dispatchMessage(Handler.java:101)
at android.os.Looper.loop(Looper.java:166)
at android.app.ActivityThread.main(ActivityThread.java:7425)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run
(Zygote.java:245)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:921)
Caused by: java.lang.UnsupportedOperationException:
TextureView doesn't support displaying a background drawable
at android.view.TextureView.setBackgroundDrawable(TextureView.java:321)
at android.view.View.setBackground(View.java:20532)
at android.view.View.<init>(View.java:5232)
at android.view.View.<init>(View.java:4647)
at android.view.View.<init>(View.java:4626)
at android.view.TextureView.<init>(TextureView.java:148)
at md5773532591b176ca6c4550eebd08312bd.AutoFitTextureView.<init> .
(AutoFitTextureView.java:29)
..
This is the AutoFitTextureView.cs 这是AutoFitTextureView.cs
public class AutoFitTextureView : TextureView
{
private int mRatioWidth = 0;
private int mRatioHeight = 0;........ link to pastebin
Code AutoFitTextureView 代码AutoFitTextureView
And This is the xml 这是xml
<AutoFitTextureView
android:id="@+id/camera2_content"
android:layout_below="@id/header2_wrap"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentLeft="true"/>........... link to pastebin
i call the xml in Camera2BaseFragment so: 我在Camera2BaseFragment中将xml称为:
public override View OnCreateView(LayoutInflater inflater, ViewGroup
container, Bundle savedInstanceState)
{
return inflater.Inflate(Resource.Layout.Camera2BasicFragment,
container, false);
}
i try to deleted the "AutoTextView" in xml and the inflate works. 我尝试删除xml中的“ AutoTextView”,然后进行充气。 How can i solve the problem?
我该如何解决这个问题? Thanks.
谢谢。
The Error java.lang.reflect.InvocationTargetException
usually means that you have not initialized the context properly 错误
java.lang.reflect.InvocationTargetException
通常表示您尚未正确初始化上下文
Do something like this: 做这样的事情:
public class AutoFitTextureView : TextureView
{
private int mRatioWidth = 0;
private int mRatioHeight = 0;
Context mContext;
public AutoFitTextureView(Android.Content.Context context) : base(context, null)
{
init(context, attrs);
}
public AutoFitTextureView(Android.Content.Context context, IAttributeSet attrs) : base(context, attrs, 0)
{
init(context, attrs);
}
public AutoFitTextureView(Android.Content.Context context, IAttributeSet attrs, int defStyle) : base(context,attrs,
defStyle)
{
init(context, attrs);
}
private void init(Context ctx, Android.Util.IAttributeSet attrs)
{
mContext = ctx;
}
public void SetAspectRatio(int width, int height)
{
if (width == 0 || height == 0)
throw new ArgumentException("Size cannot be negative.");
mRatioWidth = width;
mRatioHeight = height;
RequestLayout();
}
protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec)
{
base.OnMeasure(widthMeasureSpec, heightMeasureSpec);
int width = MeasureSpec.GetSize(widthMeasureSpec);
int height = MeasureSpec.GetSize(heightMeasureSpec);
if (0 == mRatioWidth || 0 == mRatioHeight)
{
SetMeasuredDimension(width, height);
}
else
{
if (width < (float)height * mRatioWidth / (float)mRatioHeight)
{
SetMeasuredDimension(width, width * mRatioHeight / mRatioWidth);
}
else
{
SetMeasuredDimension(height * mRatioWidth / mRatioHeight, height);
}
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.