我有一个带有ListView的Xamarin.Forms应用程序。 当一个listItem被按下时,在Android上有一个连锁反应。要求抑制这种波动。
我在Android项目中尝试了一种风格:
linearLayoutManager = new LinearLayoutManager(context) {
@Override
public boolean canScrollVertically() {
return true;
}
};
recyclerView.setLayoutManager(linearLayoutManager);
linearLayoutManager.scrollToPosition(youePositionInTheAdapter); // where youPositionInTheAdapter is the position you want to scroll to
没有运气 - 风格不会被捡起来。 我尝试了一个自定义的ViewCell渲染器:
<style name="MainTheme" parent="MainTheme.Base">
<item name="android:listViewStyle">@style/ListViewStyle.Light</item>
</style>
<style name="ListViewStyle.Light" parent="android:style/Widget.ListView">
<item name="android:listSelector">@drawable/actionbar_background_green</item>
</style>
这也不起作用。涟漪效应仍然存在,只有当纹波结束时,所选项目才会获得新的背景颜色。
这个问题涉及Xamarin.Forms,而不是Xamarin.Android和Java。
答案 0 :(得分:1)
这是一个古老的问题,但是我希望这个答案可以帮助其他人寻找解决方案。您可以将Frame
添加到ViewCell
中以将其完全填满,然后向该Frame添加一个空的点击手势识别器。这样,ViewCell不会检测到任何轻拍,因此不会触发波纹效果。
布局示例:
<ListView ItemsSource="{Binding ItemsSource}" HasUnevenRows="True" SelectionMode="None">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<AbsoluteLayout>
<Frame AbsoluteLayout.LayoutFlags="All" AbsoluteLayout.LayoutBounds="0,0,1,1" BackgroundColor="Transparent">
<Frame.GestureRecognizers>
<TapGestureRecognizer/>
</Frame.GestureRecognizers>
</Frame>
<!-- Your controls !-->
</AbsoluteLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>