如何更改交换机的Widget大小 [英] How to change the size of a Switch Widget

查看:196
本文介绍了如何更改交换机的Widget大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在冰淇淋三明治一个开关的Widget介绍显示的开启关闭滑块。

In Ice Cream Sandwich a Switch Widget was introduced that displays an On Off Slider.

我说这样的开关:

<Switch 
    android:layout_width="fill_parent"
    android:layout_height="48dp"
    android:textStyle="bold"
    android:thumb="@drawable/switch_thumb_selector"
    android:track="@drawable/switch_bg_selector" />

这条赛道和拇指可绘制九片图像应该扩展到所有可能的尺寸的。 我希望交换机将扩展到指定的范围内的最大尺寸,但它好像在可绘制只是中心提供的空间内。

The track and thumb drawables are nine patch images that should scale to all possible sizes. I hoped that the Switch would scale to the maximum size inside the given bounds, but it seems as if the drawables are just centered inside the supplied space.

是否有可能增加开关的尺寸,使其出现较大?

Is it possible to increase the size of the Switch to make it appear bigger?

推荐答案

我想,我终于想通了这一点:

I think I finally figured this out:

    TEXTSIZE =... /&GT; :开关机器人;
  1. 切换字幕大小由&LT控制
  2. 切换拇指文字的大小由&LT控制,开关安卓switchTextAppearance =... /&GT; 。煮了一个属于自己的风格。这种风格很重要,因为它控制着拇指(以后会更多)的总宽度。
  3. 在总开关高度由&LT控制,切换机器人:跟踪 =@可绘制/ shape_mythumb... /&GT; 。你用九个补丁,我怀疑就是为什么你有一个问题。我用了一个&LT;形机器人:形状=矩形...&GT;&LT; /形状&GT; 和成功
  4. 拇指绘制的高度&LT;开关安卓拇指=... /&GT; 进行调整,以配合轨道的高度。拇指的可拉伸的高度是唯一重要的拇指的形状。它不影响开关的高度。
  1. Switch caption size is controlled by <switch android:textSize=""... />
  2. Switch thumb text size is controlled by <switch android:switchTextAppearance="".../>. Cook up a style of your own. This style is important because it controls the overall width of the thumb (more on this later).
  3. Overall switch height is controlled by <switch android:track="@drawable/shape_mythumb".../>. You used a nine patch, which I suspect is why you are having a problem. I used a <shape android:shape="rectangle"...></shape> and was successful.
  4. The height of the thumb drawable <switch android:thumb="".../> is adjusted to match the height of the track. The height of the thumb's drawable is only important to the shape of the thumb. It does not effect the height of the switch.

因此​​,这里是我发现:

So here's what I found:

  1. 使用&LT;形状&GT; ...&LT; /形状&GT; 可绘制两个开关拇指和切换曲目
  2. 两个可绘制的宽度是irrelavant。我设置矿0dp
  3. 轨道的高度决定了交换机的整体高度。
  4. 的Andr​​oid最长的字符串:textOff 安卓纹元将确定大拇指的宽度。这决定了整个开关的宽度。开关宽度始终拇指宽度的两倍。
  5. 如果拇指文本宽度小于该轨道的高度,拇指形状将被缩小。这可以扭曲拇指的形状。如果发生这种情况,添加空格增加上的文字的关或宽度直到它至少一样宽的轨道高度。
  1. Use <shape>...</shape> drawables for both the switch thumb and switch track.
  2. The width of both drawables is irrelavant. I set mine to "0dp"
  3. The track's height determines the switch's overall height.
  4. The longest string of android:textOff or android:textOn will determine the width of the thumb. This determines the width of the entire switch. Switch width is always twice the width of the thumb.
  5. If the thumb text width is less that the height of the track, the thumb shape will be scaled down. This can distort the shape of the thumb. If this happens, add spaces to increase the width of your "off" or "on" text until it is at least as wide as your track is tall.

这是足够的信息来至少开始设计开关,你希望他们的大小和形状。让我知道,如果你想出什么。

This is enough information to at least start designing switches to the size and shape that you want them. Let me know if you figure out anything else.

这篇关于如何更改交换机的Widget大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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