Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xamarin.Android C# layout_weight error: Must specify a unit, such as "px" (Intellisense?)

A snippet of my layout:

        <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <Button
            android:text="@string/moreInfo"
            android:layout_width="wrap_content"
            android:layout_weight= "1"
            android:layout_height="wrap_content"
            android:layout_gravity="left"
            android:id="@+id/moreInfo" />

I get an IntelliSense error: Must specify a unit, such as "px" for every instance of android:layout_weight in the file. I've tried adding WeightSum to the LinearLayout and changing from int to float (though still in quotes) but the error persists.

The odd thing (to me, at least) is that I can still build/run my code on the emulator. My guess is that it's something in IntelliSense, and I don't like outstanding errors, even if they're erroneous...

Using VS2019 Community.

like image 328
Michael Coury Avatar asked Aug 14 '20 20:08

Michael Coury


People also ask

What is Xamarin C?

Xamarin is an open-source platform for building modern and performant applications for iOS, Android, and Windows with . NET. Xamarin is an abstraction layer that manages communication of shared code with underlying platform code.

Is Xamarin similar to C#?

Technically speaking, Xamarin uses C# and native libraries wrapped in the . Net layer for cross-platform app development. Such applications are often compared to native for both iOS and Android mobile development platforms in terms of performance and user experience.

Does Xamarin use C++?

Visual C++ for cross-platform mobile development enables the C/C++ and C# code to be built as part of the same solution, offering many advantages including a unified debugging experience. Microsoft has used C/C++ and Xamarin in this way to deliver apps such as Hyperlapse Mobile and Pix Camera.

Is Xamarin good for Android development?

Since its appearance in 2011, Xamarin has become a great option for cross-platform app development, a faster way to build iOS, Android, and Windows apps.

What is Xamarin Android?

Xamarin.Android will create native Android applications using modern language (C#), .NET Base Class Library Visual Studio. Xamarin is a cross-platform development tool. It solves dilemmas many developers face when developing cross-platform apps: separate coding languages and UI paradigms.

Can I use C libraries in Xamarin?

Use C/C++ libraries with Xamarin. Overview. Xamarin enables developers to create cross-platform native mobile apps with Visual Studio. Generally, C# bindings are used to expose existing platform components to developers. However, there are times when Xamarin apps need to work with existing codebases.

How to create Xamarin Android app with imageview?

In this article, you will create Xamarin Android, using your own camera app and showing Imageview in the last captured image. Select Blank app. Give project name and project location. Step 2- Open Solution Explorer-> Project Name->Resources->Layout->Main.axml. Click Open Design View.

How do I run Xamarin forms on a mobile device?

In Solution Explorer, CONTROL + CLICK on the target ( MathFuncsApp.Android or MathFuncs.iOS) for initial testing, then choose Set As Startup Project. Choose the preferred device or Simulator / Emulator. Run the solution ( COMMAND + RETURN) to validate that the templated Xamarin.Forms project builds and runs okay.


1 Answers

this is a bug in Visual Studio and its new Analyzers. Other than the annoyance of it showing up in the error list it shouldn't affect the app build or running it.

Sincerely the lame developer that wrote the bug :)

PS, I'm really sorry for the trouble and am working on fixing it right now.

PPS, I'll make sure to add a unit test.

Update: A fix is in and should land in one of the next couple 16.9 previews

like image 86
sshaw Avatar answered Oct 01 '22 17:10

sshaw