我想用CarouselView來創建一個水平的ListView,因為我的一個客戶不喜歡我在他們專案中實作的垂直ListView。我試著按照幾個教程來做,但都沒有成功。
我有一種預感,問題出在我下載的nuget包或我在xml中使用的命名空間上。我在一個 Xamarin Android 應用程式中使用 Visual studio 2019。
以下是我為旋轉木馬視圖下載的nuget包串列:
<CarouselView
CarouselView.FormsPlugin
CarouselView.FormsPlugin.Fix
Xamarin.Forms v5.0.0.2083
以下是我content_main.xml中的代碼
<?xml version="1.0"/span> encoding="utf-8"/span>?
<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"/span>
xmlns:forms="clr-namespace:Xamarin.Forms;assembly=Xamarin.Forms.CarouselView"/span>
android:layout_width="match_parent"/span>
android:layout_height="match_parent"/span>
app:layout_behavior="@string/appbar_scrolling_view_behavior"。
tools:showIn="@layout/activity_main">
<TextView
android:layout_width="wrap_content"/span>
android:layout_height="wrap_content"/span>
android:layout_centerInParent="true"/span>
android:text="Hello World!" />
<forms:CarouselView
android:layout_width="wrap_content"/span>
android:layout_height="wrap_content"/>
</RelativeLayout>
除了你在創建新專案時得到的默認頁面外,我在這里添加的是xmlns:forms行,用于命名空間和CarouselView標簽本身。
在我的OnCreate后面的代碼中,我有以下內容:
base.OnCreate(saidInstanceState);
Xamarin.Essentials.Platform.Init(this, savedInstanceState)。
CarouselViewRenderer.Init()。
SetContentView(Resource.Layout.activity_main)。
再次,我在這里添加的只是對CarouselViewRenderer的Init呼叫。當SetContentView被呼叫時,我得到的錯誤是 "Error inflating class CarouselView"。
請讓我知道我是否忽略了一些愚蠢的東西。我無法讓Intellisense在xml中提示CarouselView,所以我確信有什么問題。也許它找不到這個標簽?這就是為什么我在想這可能是一個命名空間的問題。
我嘗試了什么:
我試著調換了 Init 的呼叫,并以不同的順序呼叫,但沒有任何效果。
我在 GitHub 論壇中尋找與此類似的問題,但似乎沒有解決方案適用于我的情況。
我試著將 xml 中的標簽名稱改為類似 CarouselVie 的名稱,但沒有'w',我得到了同樣的錯誤,這意味著它可能一開始就沒有找到那個標簽。
我試著改變命名空間,并尋找不同的nuget包來下載,但還是沒有效果。
uj5u.com熱心網友回復:
從檔案什么是Xamarin.Forms?,我們知道
Xamarin.Forms是一個開源的UI框架。Xamarin.Forms允許 Xamarin.Forms允許開發者從單一的共享代碼庫中構建Xamarin.Android、Xamarin.iOS和Windows因此,你可以在forms'app中使用Xamarin Forms控制元件(Xamarin.Forms允許開發人員從一個共享代碼庫中構建Xamarin.Android.iOS和Windows應用程式。
Xamarin.Forms允許開發者在XAML中創建用戶界面,并在C#中撰寫后臺代碼。 在C#中撰寫后臺代碼。這些界面在每個平臺上被呈現為高性能的本地
在運行時,Xamarin.Forms允許開發人員在XAML中創建用戶界面,并在C#中撰寫后臺代碼。
在運行時,Xamarin.Forms利用平臺渲染器來將跨平臺的UI元素轉換成 Xamarin.Forms利用平臺渲染器將跨平臺的UI元素轉換為Xamarin.Android上的本地控制元件。 Xamarin.iOS和UWP上的本地控制元件。這使得開發者能夠獲得原生的外觀。 感覺和性能,同時實作代碼共享的好處。
CarouselView),并將該app部署到你的android設備或ios設備上。
從你發布的上述描述中,我認為你對CarouselView的用法感到困惑。
由于CarouselView是xamarin表單的一個控制元件,你應該在xamarin表單的應用中使用它,而不是在Android中參考它。
關于如何使用CarouselView,你可以參考官方檔案。Xamarin.Forms CarouselView。
并且在這個檔案中包含了一個示例(Xamarin.Forms - CarouselView),你可以下載它并將其部署到你的Android設備上,這將有助于你更好地理解它。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/317284.html
標籤:
