Xamarin相对较新。
我的应用程序页面上有一个Slider控件。在Android中(到目前为止,我仅测试过O / S)。但是我只看到缩略图。我看不到水平线。这意味着用户看不到它是滑块!
我发现了这个https://github.com/opendatakit/collect/pull/2085,似乎表明这是更高版本的Android上的错误,但是有一种解决方法。
引用:“我们唯一需要做的就是向我们的布局文件中添加一个android:layerType =“ software”属性”
我不确定该怎么做。什么布局文件?在哪里创建“布局文件”。有人可以帮忙吗?谢谢。
答案 0 :(得分:0)
在网上搜索后,我创建了一个客户Slider Renderer
public class CustomSliderRenderer : SliderRenderer
{
/// <summary>
/// Instantiate a CustomSliderRenderer
/// </summary>
/// <param name="context">The context to use</param>
public CustomSliderRenderer(Context context)
: base(context) { }
/// <summary>
/// Called when the Slider changes
/// </summary>
/// <param name="e">The details of the change</param>
protected override void OnElementChanged(ElementChangedEventArgs<Slider> e)
{
base.OnElementChanged(e);
if (!(e.OldElement is null) || e.NewElement is null)
return;
// The line colour to the left of the image
Control.ProgressTintList = ColorStateList.ValueOf(Color.Black.ToAndroid());
Control.ProgressTintMode = PorterDuff.Mode.SrcIn;
// The line colour to the right of the image
Control.ProgressBackgroundTintList = ColorStateList.ValueOf(Color.Black.ToAndroid());
Control.ProgressBackgroundTintMode = PorterDuff.Mode.SrcIn;
}
/// <summary>
/// Called when the Slider is layed out.
/// </summary>
/// <param name="changed">True if the layout has changed, else false</param>
/// <param name="left">The left of the Slider</param>
/// <param name="top">The top of the Slider</param>
/// <param name="right">The right of the Slider</param>
/// <param name="bottom">The bottom of the Slider</param>
protected override void OnLayout(bool changed, int left, int top, int right, int bottom)
{
base.OnLayout(changed, left, top, right, bottom);
if (Build.VERSION.SdkInt >= BuildVersionCodes.JellyBean && !(Control is null))
{
var thumb = Control.Thumb;
int thumbTop = Control.Height / 2 - thumb.IntrinsicHeight / 2;
thumb.SetBounds(thumb.Bounds.Left, thumbTop, thumb.Bounds.Left + thumb.IntrinsicWidth, thumbTop + thumb.IntrinsicHeight);
}
}
}
然后在XAML中
<Slider
Grid.Row="7"
Grid.Column="0"
Grid.ColumnSpan="2"
x:Name="DaysAbandonedVisible"
Value="{Binding DaysAbandonedVisible}"
Maximum="60"
Minimum="0"
ThumbImageSource="Slider.png"/>
Slider.png只是一个黑色圆圈,大于默认的粉红色圆圈。这具有显示线条的效果(左侧为黑色,右侧为“浅”黑色)。这些颜色分别位于Control.ProgressTintList和Control.ProgressBackgroundTintList中。