调整大小/按比例缩小的Andr​​oid窗口小部件(的DatePicker和TimePicker) [英] Resizing/Scaling Down Android Widgets (DatePicker and TimePicker)

查看:251
本文介绍了调整大小/按比例缩小的Andr​​oid窗口小部件(的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.

我正在寻找这样做,现在是调整一些默认的Andr​​oid窗口小部件,具体的DatePicker和TimePicker的,在活动中使用。但据我可以看到修改或者选择器的宽度或高度(负方向)导致裁剪视图,而不是小窗口的缩放/拉伸视图的唯一结果。

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.

我打开我自己的我自己的自定义窗口小部件,但我真的preFER保持这个项目简单,干净越好,搭配Android操作系统的用户界面尽可能,所以使用本机的DatePicker和TimePicker似乎是一个合乎逻辑的选择我。如果有人知道如何去衡量这些小部件减少,而不是种植他们,我真的AP preciate吧。

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.

感谢。

推荐答案

这是一个非常糟糕的黑客攻击,但它应该工作: 创建一个新的视图扩展的LinearLayout和覆盖法[getChildStaticTransformation] [1]和setStaticTransformationsEnabled明确为真。

It is a very bad hack, but it should work: Create a new view extending LinearLayout and overwrite method [getChildStaticTransformation][1] and setStaticTransformationsEnabled explicit to true.

在getChildStaticTransformation你可以操纵tranformation参数缩小您的扩展的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 oder something else as a child of this view.

例如:

 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;
}

}

[1]:<一href="http://developer.android.com/intl/de/reference/android/view/ViewGroup.html#getChildStaticTransformation(android.view.View">http://developer.android.com/intl/de/reference/android/view/ViewGroup.html#getChildStaticTransformation(android.view.View, android.view.animation.Transformation)

[1]: http://developer.android.com/intl/de/reference/android/view/ViewGroup.html#getChildStaticTransformation(android.view.View, android.view.animation.Transformation)

这篇关于调整大小/按比例缩小的Andr​​oid窗口小部件(的DatePicker和TimePicker)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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