简体   繁体   中英

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.

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

Same error for me since i update 16.7.1, it's happening in each axml files. I believed it's due to update so i wait the next update but it's always occured in 16.7.2.

Please note that this solution is just a half measure until this issue is fixed.

Solution that worked for me was to disable IntelliSense Analysis in VS.

Simply go to Tools/Options/Text Editor/Android XML/Advanced and uncheck Enable layout diagnostics in Analysis

Backside of this approach is that IntelliSense does not check your code spelling at all.

Just tried your code in my VS 2019 Community and no IntelliSense errors for me.

Could be IntelliSense cache?

  1. Close VS
  2. Delete.vs folder in solution root directory
  3. Start VS

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM