右侧和文本上方带有向下图标的选择器 - Android [英] Picker with down icon on the right and over the text - Android

查看:51
本文介绍了右侧和文本上方带有向下图标的选择器 - Android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从这个精彩的 post 在 Xamarin Forms 项目中,但是当picker中的文本很长(比picker控件的宽度)时,文本与向下的图像重叠,看起来很糟糕.

I successfully implemented the picker with down icon on the right from this wonderful post in Xamarin Forms project, but when the text in picker is long (than the picker control's width), the text overlaps the down image, which looks very bad.

基本上向下图标可绘制图像设置为背景可绘制,因此我尝试在自定义渲染器中使用 Control.Foreground,但出现此错误 - Java.Lang.LinkageError:无非静态方法".

Basically the down icon drawable image is set as background drawable, so I tried using Control.Foreground in the custom renderer, but I got this error - "Java.Lang.LinkageError: no non-static method".

...
if (Control != null && this.Element != null && !string.IsNullOrEmpty(element.Image))
              Control.Background = AddPickerStyles(element.Image);
...

请帮忙.如果您还指出文本省略号的任何解决方案(即,像iOS这样的选择器中长文本的点),这将非常有帮助提前致谢

Please assist. It would be very helpful, if you point out any solution for text ellipsis also (ie.., dots for long texts in picker like iOS) Thanks in advance

注意:这在 iOS 中显然不是问题.

NOTE: This is obviously not a problem in iOS.

推荐答案

我最终使用了一个网格,该网格在 xamarin 论坛讨论中给出的每列中都有一个选择器和图像.这很好用!

I ended up using a Grid that has a picker and image in each column as given in a xamarin forums discussion. This works fine!

<Grid>
   <Grid.ColumnDefinitions>
      <ColumnDefinition Width="1*"/>
   </Grid.ColumnDefinitions>
   <userControl:BindablePicker Grid.Row="0" Grid.Column="0" ItemsSource="{Binding x, Mode=TwoWay}" SelectedItem="{Binding x}"/>
   <Image Grid.Row="0" Grid.Column="0" Source="arrow.png" HeightRequest="x" WidthRequest="x" InputTransparent="True" HorizontalOptions="End" VerticalOptions="Center"/>
</Grid>

注意:我在我的案例中使用了上面的 XAML 代码,因为我的下拉菜单数量很少,也是因为我没有任何其他方法可以解决这个问题.

NOTE : I used this above XAML code for my case as I have very little number of dropdowns, also because I didnt have any other way to overcome this problem.

这篇关于右侧和文本上方带有向下图标的选择器 - Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆