编辑:TLTR;这是一条漫长而艰难的道路。原来Visual Studio / Xamarin / Android / SOMETHING ..不喜欢我将下载的.xml文件移到我的drawable文件夹中,只是将它们重命名为.axml,所以创建了新的.axml文件并将.xml布局粘贴到那里似乎已经解决了所有问题。
.....
我认为我的版式有问题。该项目无法生成,但不会显示任何错误。
我注意到的是..如果删除三个引用我的axml和布局ID的代码块,则将构建项目(请参阅下面的第一个代码部分中的注释)..如果我从我的随机文件中获取了axml和布局ID,项目(而不是我从在线示例中刚刚导入的项目)也会构建。
我认为问题可能是:
@ dimens,@ colors等中的一个破坏了我的布局,但是我尝试从.axml文件中删除它们,但是没有运气。
我的布局可能在第一个Layout对象(也称为RelativeLayout xmlns:android =
在常规Android和Xamarin android中,我没有捕捉到的布局有所不同
注意:
必须删除/替换所有三个代码段
我已重新启动计算机,重新启动了VS,已被obj / bin文件夹删除等。
我正在重新创建此项目,但使用Xamarin Android C#:https://www.androidhive.info/2016/05/android-build-intro-slider-app/
我的Activity OnCreate函数中包含以下代码:(请注意,我指出可以删除哪三个代码块才能使构建正常工作)
class StartUpDialogs : Activity
{
...
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
// Making notification bar transparent
if ((int)Build.VERSION.SdkInt >= 21)
{
Window.DecorView.SystemUiVisibility = (StatusBarVisibility)(SystemUiFlags.LayoutStable | SystemUiFlags.LayoutFullscreen);
}
//REMOVING THE FOLLOWING THREE CODE BLOCKS ALLOWS IT TO BUILD
// Also replacing with Ids and Layouts not from this example work too
{
SetContentView(Resource.Layout.activity_welcome);
viewPager = FindViewById<ViewPager>(Resource.Id.view_pager);
dotsLayout = FindViewById<LinearLayout>(Resource.Id.layoutDots);
btnSkip = FindViewById<Button>(Resource.Id.btn_skip);
btnNext = FindViewById<Button>(Resource.Id.btn_next);
// layouts of all welcome sliders
// add few more layouts if you want
layouts = new int[]{
Resource.Layout.welcome_slide1,
Resource.Layout.welcome_slide2,
Resource.Layout.welcome_slide3,
Resource.Layout.welcome_slide4};
}
myViewPagerAdapter = new StartUpDialogAdapter(this, layouts);
viewPager.Adapter = (myViewPagerAdapter);
viewPager.PageSelected += OnPageChange;
btnSkip.Click += OnSkip;
btnNext.Click += GoNext;
}
...
}
以下是布局文件:
activity_welcome.axml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:showIn="@layout/activity_welcome">
<android.support.v4.view.ViewPager
android:id="@+id/view_pager"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<LinearLayout
android:id="@+id/layoutDots"
android:layout_width="match_parent"
android:layout_height="@dimen/dots_height"
android:layout_alignParentBottom="true"
android:layout_marginBottom="@dimen/dots_margin_bottom"
android:gravity="center"
android:orientation="horizontal"></LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:alpha=".5"
android:layout_above="@id/layoutDots"
android:background="@android:color/white" />
<Button
android:id="@+id/btn_next"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:background="@null"
android:text="@string/next"
android:textColor="@android:color/white" />
<Button
android:id="@+id/btn_skip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:background="@null"
android:text="@string/skip"
android:textColor="@android:color/white" />
</RelativeLayout>
welcome_slide1.axml(2-4相同,除了数字分别为2、3、4)
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/bg_screen1">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:gravity="center_horizontal"
android:orientation="vertical">
<ImageView
android:layout_width="@dimen/img_width_height"
android:layout_height="@dimen/img_width_height"
android:src="@drawable/ic_food" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/slide_1_title"
android:textColor="@android:color/white"
android:textSize="@dimen/slide_title"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:paddingLeft="@dimen/desc_padding"
android:paddingRight="@dimen/desc_padding"
android:text="@string/slide_1_desc"
android:textAlignment="center"
android:textColor="@android:color/white"
android:textSize="@dimen/slide_desc" />
</LinearLayout>
</RelativeLayout>
还有我的Resource文件,以防它们损坏:(我必须将字符串数组移到strings.xml中,以便它们在我的OnCreate函数中注册,因为代码所有者项目在colors.xml中拥有它)>
colors.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FF4081</color>
<!-- Screens background color-->
<color name="bg_screen1">#f64c73</color>
<color name="bg_screen2">#20d2bb</color>
<color name="bg_screen3">#3395ff</color>
<color name="bg_screen4">#c873f4</color>
<!-- dots inactive colors -->
<color name="dot_dark_screen1">#d1395c</color>
<color name="dot_dark_screen2">#14a895</color>
<color name="dot_dark_screen3">#2278d4</color>
<color name="dot_dark_screen4">#a854d4</color>
<!-- dots active colors -->
<color name="dot_light_screen1">#f98da5</color>
<color name="dot_light_screen2">#8cf9eb</color>
<color name="dot_light_screen3">#93c6fd</color>
<color name="dot_light_screen4">#e4b5fc</color>
</resources>
dimens.xml
<resources>
<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="activity_horizontal_margin">16dp</dimen>
<dimen name="activity_vertical_margin">16dp</dimen>
<dimen name="fab_margin">16dp</dimen>
<dimen name="dots_height">30dp</dimen>
<dimen name="dots_margin_bottom">20dp</dimen>
<dimen name="img_width_height">120dp</dimen>
<dimen name="slide_title">30dp</dimen>
<dimen name="slide_desc">16dp</dimen>
<dimen name="desc_padding">40dp</dimen>
</resources>
Strings.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">XXX</string>
<string name="user_spinner_prompt">Select Account</string>
<string name="app_name">Intro Slider</string>
<string name="title_activity_welcome">Home Screen</string>
<string name="next">NEXT</string>
<string name="skip">SKIP</string>
<string name="start">GOT IT</string>
<string name="slide_1_title">Hello Food!</string>
<string name="slide_1_desc">The easiest way to order food from your favourite restaurant!</string>
<string name="slide_2_title">Movie Tickets</string>
<string name="slide_2_desc">Book movie tickets for your family and friends!</string>
<string name="slide_3_title">Great Discounts</string>
<string name="slide_3_desc">Best discounts on every single service we offer!</string>
<string name="slide_4_title">World Travel</string>
<string name="slide_4_desc">Book tickets of any transportation and travel the world!</string>
<string name="play_again_desc">To see the welcome slider again, goto Settings -> apps -> welcome slider -> clear data</string>
<string name="play_again">Play Again</string>
<string-array name="array_dot_active">
<item>@color/dot_light_screen1</item>
<item>@color/dot_light_screen2</item>
<item>@color/dot_light_screen3</item>
<item>@color/dot_light_screen4</item>
</string-array>
<string-array name="array_dot_inactive">
<item>@color/dot_dark_screen1</item>
<item>@color/dot_dark_screen2</item>
<item>@color/dot_dark_screen3</item>
<item>@color/dot_dark_screen4</item>
</string-array>
</resources>