none
Visual Studio 2019编写的安卓程序,生成失败 RRS feed

  • Question

  • 下载实例不改动任何能够编译成功,稍加改动无法编译成功。

    布局代码:

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <TextView
            android:text="请输入拱高L:"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/textView1" />
        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/GongGao"
            android:text="5" />
        <TextView
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/TranslatedPhoneWord"
            android:text="请输入弦长L" />
        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/xianchang" />
        <TextView
            android:text="半径R="
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:layout_width="match_parent"
            android:layout_height="50"
            android:id="@+id/BanJing" />
        <Button
            android:text="计算半径"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/JiSuan" />
    </LinearLayout>

    入口代码:

                             

    using System;
    using Android.App;
    using Android.OS;
    using Android.Widget;


    namespace Phoneword
    {
        [Activity(Label = "Phone Word", MainLauncher = true, Icon = "@drawable/icon")]
        public class MainActivity : Activity
        {
            protected override void OnCreate(Bundle savedInstanceState)
            {
                base.OnCreate(savedInstanceState);

                // Set our view from the "main" layout resource
                SetContentView(Resource.Layout.Main);

                // Get our UI controls from the loaded layout
                EditText h = FindViewById<EditText>(Resource.Id.GongGao);
                EditText l = FindViewById<EditText>(Resource.Id.xianchang);
                Button bt = FindViewById<Button>(Resource.Id.JiSuan);
    TextView tv = FindViewById<TextView>(Resource.Id.BanJing);

    string translatedNumber = string.Empty;

                bt.Click += (sender, e) =>
                {

                    try
                    {
                        if (double.Parse(h.Text) > 0 && double.Parse(l.Text) > 0)
                        {
                            tv.Text = "半径R="+Jisan(double.Parse(h.Text), double.Parse(l.Text));
                        }

                    }
                    catch (Exception ex)
                    {
                        tv.Text = ex.ToString();
                    }
                };
            }

            private string Jisan(double h, double l)
            {
               return ((h / 2 + l * l / 8 / h).ToString());
            }
        }
    }

    其余代码为自动生成。

    Monday, July 15, 2019 5:40 PM

All replies

  • Hi mr.yitongyu,

    Sorry for delay in reply.

    According to your description, I have build your code in my side, but it always builds failly. Please change 

    android:layout_height="50" to android:layout_height="50dp".

    And it could build successfully in my side. Then I change other values, it could also build successfully.

    If this issue persists, please restart the visual studio.

    Look forward to your feedback.

    Best Regards,

    Dylan


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com

    Thursday, July 18, 2019 3:28 AM
  • Hi mr.yitongyu,

    Sorry for bothering you.

    I just want to confirm if this issue is solved, if not, please feel free to let us know, we will try our best to help you out.

    BTW, if you think the reply is helpful and could please mark it as answer, that benefits for other community members who meet the similar issue, thanks in advance.

    Have a nice day!

    Best Regards,

    Dylan


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com


    Monday, August 5, 2019 7:51 AM