代码之家  ›  专栏  ›  技术社区  ›  Post Impatica

Android原生CardView可以用在Xamarin表单XAML中吗?

  •  0
  • Post Impatica  · 技术社区  · 8 年前

    我已经尽我所能搞乱了,但是我找不到在xamarin.forms xaml中嵌入本地xamarin.android CardView控件的方法。以下是我的代码:

    我的命名空间

    xmlns:androidWidget="clr-namespace:Android.Widget;assembly=Mono.Android;targetPlatform=Android"    
    xmlns:androidWidgetv7="clr-namespace:Android.Support.V7.Widget;assembly=Xamarin.Android.Support.v7.CardView;targetPlatform=Android"
    xmlns:androidLocal="clr-namespace:MyApp.Droid;assembly=MyApp.Android;targetPlatform=Android"
    

    我的Xaml

    <androidWidgetv7:CardView x:Arguments="{x:Static androidLocal:MainActivity.Instance}" View.HorizontalOptions="Center" View.WidthRequest="600" View.HeightRequest="300">
        <androidWidget:TextView x:Arguments="{x:Static androidLocal:MainActivity.Instance}" Text="Simple Native Color Picker" TextSize="24" View.HorizontalOptions="Center"/>
    </androidWidgetv7:CardView>
    

    我得到以下错误

    Exception is: XamlParseException - Position 32:18. Can not set the content of androidWidgetv7:CardView as it doesn't have a ContentPropertyAttribute
    

    网上没有任何例子说明如何做到这一点。有人知道吗?

    1 回复  |  直到 8 年前
        1
  •  1
  •   LeRoy    8 年前

    你不能。但是你可以像他们那样实现一个类似的版本 here .

    你可以找到其他版本 here here .

    别指望这里有android动画/触摸手势。

    <?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"
        android:gravity="center_horizontal"
        android:padding="5dp">
        <android.support.v7.widget.CardView
            android:layout_width="fill_parent"
            android:layout_height="245dp"
            android:layout_gravity="center_horizontal">
            <TextView
                android:text="Basic CardView"
                android:layout_marginTop="0dp"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:gravity="center"
                android:layout_centerVertical="true"
                android:layout_alignParentRight="true"
                android:layout_alignParentEnd="true" />
        </android.support.v7.widget.CardView>
    </LinearLayout>
    

    enter image description here

    推荐文章