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)
基础教程推荐
- 如何将图像从一项活动发送到另一项活动? 2022-01-01
- iOS - UINavigationController 添加多个正确的项目? 2022-01-01
- Play 商店的设备兼容性问题 2022-01-01
- navigationItem.backBarButtonItem 不工作?为什么上一个菜单仍然显示为按钮? 2022-01-01
- 如何比较两个 NSDate:哪个是最近的? 2022-01-01
- Android Volley - 如何动画图像加载? 2022-01-01
- Xcode UIView.init(frame:) 只能在主线程中使用 2022-01-01
- UIImage 在开始时不适合 UIScrollView 2022-01-01
- 为什么姜饼模拟器方向卡在应用程序中? 2022-01-01
- SwiftUI-ScrollViewReader的ScrollTo不滚动 2022-01-01
