Resizing/Scaling Down Android Widgets (DatePicker and TimePicker)

后端 未结 1 2050
-上瘾入骨i
-上瘾入骨i 2021-02-06 19:23

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.

What I\'m looking to

1条回答
  •  清歌不尽
    2021-02-06 19:43

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

    In the method getChildStaticTransformation you can manipulate the tranformation parameter to scale down all the content of your extended LinearLayout.

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

    0 讨论(0)
提交回复
热议问题