Resizing/Scaling Down Android Widgets (DatePicker and TimePicker)(调整/缩小 Android 小部件(DatePicker 和 TimePicker))
问题描述
我不确定这是否可行,并且我找不到基于它的主题,但如果在给我一个链接之前已经回答,那就是这样.
I'm not sure if this is possible, and I couldn't find a topic based on it, but if it's been answered before drop me a link and that will be that.
我现在要做的是调整一些默认 Android 小部件的大小,特别是 DatePicker 和 TimePicker,以便在 Activity 中使用.但据我所知,修改任一 Picker 的宽度或高度(在负方向)的唯一结果会导致裁剪视图,而不是小部件的缩放/拉伸视图.
What I'm looking to do right now is resize some of the default Android widgets, specifically DatePicker and TimePicker, to use in an Activity. But as far as I can see the only result of modifying the width or height of either Picker (in a negative direction) results in a cropped view, rather than a scaled/stretched view of the widget.
我对我自己的自定义小部件持开放态度,但我真的更希望让这个项目尽可能简单和干净,尽可能匹配 Android OS UI,所以使用原生 DatePicker 和 TimePicker 似乎对我来说是一个合乎逻辑的选择.如果有人知道如何缩小这些小部件而不是裁剪它们,我将不胜感激.
I am open to my own custom widgets of my own, but I would really prefer to keep this project as simple and clean as possible, matching the Android OS UI as much as possible, so using the native DatePicker and TimePicker seems like a logical choice to me. If anyone knows how to scale these widgets down rather than cropping them, I'd really appreciate it.
谢谢.
推荐答案
这是一个非常糟糕的 hack,但它应该可以工作:创建一个扩展 LinearLayout
的新视图,覆盖方法 getChildStaticTransformation
和 setStaticTransformationsEnabled
显式为 true
.
It is a very bad hack, but it should work:
Create a new view extending LinearLayout
, overwrite method getChildStaticTransformation
and setStaticTransformationsEnabled
explicit to true
.
在方法 getChildStaticTransformation
中,您可以操纵 transformation 参数来缩小扩展 LinearLayout 的所有内容.
In the method getChildStaticTransformation
you can manipulate the tranformation parameter to scale down all the content of your extended LinearLayout.
然后添加 DatePicker
或其他内容作为此视图的子项.
And then add the DatePicker
or something else as a child of this view.
EG:
public class ZoomView
extends LinearLayout
{
private float sf = 1f;
public ZoomView(final Context context, final AttributeSet attrs)
{
super(context, attrs);
setStaticTransformationsEnabled(true);
}
public ZoomView(final Context context)
{
super(context);
setStaticTransformationsEnabled(true);
}
public void setScaling(final float sf)
{
this.sf = sf;
}
@Override
protected boolean getChildStaticTransformation(final View child, final Transformation t)
{
t.clear();
t.setTransformationType(Transformation.TYPE_MATRIX);
final Matrix m = t.getMatrix();
m.setScale(this.sf, this.sf);
return true;
}
}
这篇关于调整/缩小 Android 小部件(DatePicker 和 TimePicker)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:调整/缩小 Android 小部件(DatePicker 和 TimePicker)
基础教程推荐
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01