我尝试使用以下代码创建垂直滑块,但“最大”和“最小”轨道颜色在Android上似乎不起作用(没有颜色可见,只有拇指颜色可见)。
<StackLayout Orientation="Vertical"
HorizontalOptions="FillAndExpand"
VerticalOptions="FillAndExpand">
<RelativeLayout HorizontalOptions="FillAndExpand"
VerticalOptions="FillAndExpand">
<Slider
RelativeLayout.YConstraint="{ConstraintExpression Type=RelativeToParent,
Property=Height,Factor=0,Constant=0}"
RelativeLayout.XConstraint="{ConstraintExpression Type=RelativeToParent,
Property=Width,Factor=0,Constant=0}"
RelativeLayout.HeightConstraint="{ConstraintExpression Type=RelativeToParent,
Property=Height,Factor=0.15,Constant=0}"
RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToParent,
Property=Width,Factor=1,Constant=0}"
ThumbColor="{StaticResource DataColor}"
MaximumTrackColor="{StaticResource ColorPrimary}"
MinimumTrackColor="{StaticResource ColorPrimaryDark}"
Maximum="100" Minimum="1" Margin="0,0,0,0"
AnchorX="1" AnchorY="1" Rotation="-90"
VerticalOptions="FillAndExpand"/>
</RelativeLayout>
</StackLayout>
我还尝试使用CustomRenderer自定义滑块,
protected override void OnElementChanged(ElementChangedEventArgs<Slider> e)
{
base.OnElementChanged(e);
if (e.OldElement != null || e.NewElement == null)
return;
view = (Slider)Element;
Control.ProgressDrawable = Resources.GetDrawable(
Resource.Drawable.custom_progressbar_style,
(this.Context).Theme);
}
然后
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/background">
<color android:color="#0066CC"/>
</item>
<item android:id="@android:id/progress">
<clip>
<color android:color="#009900"/>
</clip>
</item>
</layer-list>
但是在我的视图中仅显示进度色,背景似乎没有下注设置为#0066CC值。
当我将Slider的旋转度设置为0时,颜色设置正确。当旋转角度不同于0时会出现问题。
请参阅以下图片以了解问题,
Horizontal slider, working as i want
Vertical slider, not working as i want
编辑:添加一些具有不同方向的图片(我认为这有助于理解问题所在)