Android开关-如何使拇指高度大于轨道高度,怎么办? [英] Android switches - making thumb height larger than track height, how?

查看:119
本文介绍了Android开关-如何使拇指高度大于轨道高度,怎么办?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么方法可以使开关的拇指高度大于Lollipop之前的Android版本中的轨道高度吗?

Is there any way to make the height of the thumb of a switch bigger than the track height in Android versions prior to Lollipop ?

我实质上是在尝试创建Kitkat中的一个类似材料设计的开关小部件(以及较旧的版本-问题是默认情况下拇指在轨道内适合)。我已经为此工作了一段时间,但似乎无法得出正确的设计。

I am essentially trying to create a material design-like switch widget in Kitkat (and older versions- the problem here is the thumb by default 'fits' inside the track). I have been working on this for quite some time now but I can't seem to arrive at the correct design.

我遵循了这篇SO帖子中的解决方案:如何更改Switch小部件的大小

I followed the solutions on this SO post: How to change the size of a Switch Widget.

任何建议或解决方案将不胜感激。

Any suggestions or a solution would be most appreciated.

推荐答案

我在轨迹可绘制形状中添加了一个透明笔触,导致轨迹周围出现填充:

I added a transparent stroke to my track drawable shape which results in a padding around the track:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
       android:shape="rectangle">
    <solid android:color="@color/track_color"/>
    <size android:height="@dimen/track_height"  />
    <size android:width="@dimen/track_width"  />

    <!-- results in the track looking smaller than the thumb -->
    <stroke
        android:width="6dp"
        android:color="#00ffffff"/>
</shape>

这篇关于Android开关-如何使拇指高度大于轨道高度,怎么办?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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