Я пытаюсь использовать пакет nuget TouchView. У меня это работает в проекте iOS, но я не могу получить те же функции для работы с Android. Образец приложения из https://github.com/AndreiMisiukevich/TouchEffect работает, но новый проект не работает.
Я добавил nuget TouchView 4.1.3 в свой проект Xamarin (.net standard), а также в Androidproject.
В MainActivity.cs вот мой OnCreate:
protected override void OnCreate(Bundle savedInstanceState)
{
TabLayoutResource = Resource.Layout.Tabbar;
ToolbarResource = Resource.Layout.Toolbar;
base.OnCreate(savedInstanceState);
global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
TouchEffectPreserver.Preserve();
LoadApplication(new App());
}
В общем проекте вот мой MainPage.xaml:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:touch="clr-namespace:TouchEffect;assembly=TouchEffect"
BackgroundColor="White"
x:Class="TouchExample.MainPage"
Title="TouchExample">
<StackLayout>
<!-- Place new controls here -->
<Frame
BorderColor="#56bad3"
HorizontalOptions="Center"
VerticalOptions="Center"
HasShadow="false"
BackgroundColor="White"
CornerRadius="40"
HeightRequest="80"
WidthRequest="80"
Padding="0,0,0,0"
Margin="0,100,0,0"
touch:TouchEff.RegularBackgroundColor="White"
touch:TouchEff.PressedBackgroundColor="#56bad3"
touch:TouchEff.PressedScale="1"
touch:TouchEff.RippleCount="1"
touch:TouchEff.PressedTranslationX="5"
touch:TouchEff.PressedTranslationY="5"
touch:TouchEff.PressedAnimationDuration="500"
touch:TouchEff.RegularAnimationDuration="500">
<Frame.GestureRecognizers>
<TapGestureRecognizer Command="{Binding KeyCommand}" CommandParameter="1" />
</Frame.GestureRecognizers>
<Frame.Effects>
<touch:TouchEff Completed="TouchEff_Completed"/>
</Frame.Effects>
<Grid Padding="0,0,0,15" HorizontalOptions="Center" VerticalOptions="Center">
<Label Text="1" FontSize="30" TextColor="Black" HorizontalOptions="Center" VerticalOptions="Center"/>
</Grid>
</Frame>
<Frame
HorizontalOptions="Center"
VerticalOptions="Center"
HasShadow="false"
BackgroundColor="#56bad3"
CornerRadius="40"
HeightRequest="80"
WidthRequest="80"
Padding="0,0,0,0"
Margin="0,100,0,0"
touch:TouchEff.RegularBackgroundColor="#56bad3"
touch:TouchEff.PressedBackgroundColor="LightBlue"
touch:TouchEff.PressedScale="1"
touch:TouchEff.RippleCount="1"
touch:TouchEff.PressedTranslationX="5"
touch:TouchEff.PressedTranslationY="5"
touch:TouchEff.PressedAnimationDuration="500"
touch:TouchEff.RegularAnimationDuration="500">
<Frame.Effects>
<touch:TouchEff Completed="TouchEff_Completed"/>
</Frame.Effects>
<Label Text="# Pad" TextColor="White" HorizontalOptions="Center" VerticalOptions="Center" FontSize="30"/>
</Frame>
<Frame
HorizontalOptions="Center"
VerticalOptions="Center"
HasShadow="false"
BackgroundColor="Red"
CornerRadius="40"
HeightRequest="80"
WidthRequest="80"
Padding="0,0,0,0"
Margin="0,100,0,0"
touch:TouchEff.RegularBackgroundColor="Red"
touch:TouchEff.PressedBackgroundColor="DarkRed"
touch:TouchEff.PressedScale="1"
touch:TouchEff.RippleCount="1"
touch:TouchEff.PressedTranslationX="5"
touch:TouchEff.PressedTranslationY="5"
touch:TouchEff.PressedAnimationDuration="500"
touch:TouchEff.RegularAnimationDuration="500">
<Frame.Effects>
<touch:TouchEff Completed="TouchEff_Completed"/>
</Frame.Effects>
<Label Text="Hangup" TextColor="White" HorizontalOptions="Center" VerticalOptions="Center" FontSize="30"/>
</Frame>
</StackLayout>
</ContentPage>
Икод позади MainPage.xaml.cs:
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
namespace TouchExample
{
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
}
private void TouchEff_Completed(VisualElement sender, TouchEffect.EventArgs.TouchCompletedEventArgs args)
{
Debug.WriteLine("We got here!");
}
}
}
Насколько я знаю, это все, что мне нужно сделать, чтобы эффекты работали, но они этого не делают. Чего мне не хватает?
Для iOS я сделал то же самое, за исключением обновления AppDelegate.FinishedLaunching () вместо MainActivity.OnCreate (). Пример проекта iOS работает.