Skip to content Skip to sidebar Skip to footer

Xamarin Android: Android.Views.InflateException - Error When Loading Layout

I wrote a Xamarin Android app in Visual Studio to scan QR-Barcodes. I have two layouts and two lctivitys in my project. When i start the app, the emulator loads and the App starts

Solution 1:

For every android android:layout_width and android:layout_height must be added, even with constraint layout.

The problem in your xml layout is starting from your SurfaceView, you only have android:width and android:height defined in your views.

So to resolve the problem, you need to change android:width to android:layout_width and android:height to android:layout_height.


Solution 2:

I am also face this same issue and my layout does not contain any android:width and android:height properties. I missed to add theme for my activity. I solved this issue by following steps:

Create a styles.xml file under Resources\values\ folder with below codes:

<?xml version="1.0" encoding="utf-8" ?> 
<resources>
 <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    </style>
</resources>

In MainActivity.cs define the Activity attribute to leverage AppTheme like this:

[Activity(Label = "DinexFeedback", MainLauncher = true, Icon = "@drawable/icon",Theme ="@style/AppTheme")]
public class MainActivity : Android.Support.V7.App.AppCompatActivity
{
   ...
}

Updating the answer here because this might help others...


Solution 3:

Unhandled Exception: Android.Views.InflateException:

Make sure the necessary nuget package installed in visual studio.

I used card view in my project, i got this issue becoz i didn't install Xamarin.Android.Support.cardview.

so we should install all support nuget package in order to support all widgets here i use card view.

click on project -> Manage Nuget-> check out the installed pakages, if the package were not installed just search the particular package and then download it.

updated on 10/12/2018

check your layout whether all the layout fields are started with capital letter. for ex : In android we used <view> in small letter but In c# we should use <View> otherwise it throws the inflate view exception.


Post a Comment for "Xamarin Android: Android.Views.InflateException - Error When Loading Layout"