Пример #1
0
    def create_layout_params(self, child, layout):
        """ Create the LayoutParams for a child with it's requested
        layout parameters. Subclasses should override this as needed
        to handle layout specific needs.
        
        Parameters
        ----------
        child: AndroidView
            A view to create layout params for.
        layout: Dict
            A dict of layout parameters to use to create the layout.
             
        Returns
        -------
        layout_params: LayoutParams
            A LayoutParams bridge object with the requested layout options.
        
        """
        dp = self.dp
        w, h = (coerce_size(layout.get('width', 'wrap_content')),
                coerce_size(layout.get('height', 'wrap_content')))
        w = w if w < 0 else int(w * dp)
        h = h if h < 0 else int(h * dp)
        layout_params = self.layout_param_type(w, h)

        if layout.get('margin'):
            l, t, r, b = layout['margin']
            layout_params.setMargins(int(l*dp), int(t*dp),
                                     int(b*dp), int(r*dp))
        return layout_params
Пример #2
0
 def create_layout_params(self, child, layout):
     """Override as there is no (width, height) constructor."""
     if isinstance(child, AndroidFragment):
         return super().create_layout_params(child, layout)
     # Only apply to decor views
     dp = self.dp
     w, h = (
         coerce_size(layout.get("width", "match_parent")),
         coerce_size(layout.get("height", "wrap_content")),
     )
     w = w if w < 0 else int(w * dp)
     h = h if h < 0 else int(h * dp)
     # No (w,h) constructor
     params = ViewPagerLayoutParams()
     params.width = w
     params.height = h
     params.isDecor = True
     return params
Пример #3
0
 def create_layout_params(self, child, layout):
     """ Override as there is no (width, height) constructor.
     
     """
     from .android_fragment import AndroidFragment
     if isinstance(child, AndroidFragment):
         return super(AndroidViewPager,
                      self).create_layout_params(child, layout)
     # Only apply to decor views
     dp = self.dp
     w, h = (coerce_size(layout.get('width', 'match_parent')),
             coerce_size(layout.get('height', 'wrap_content')))
     w = w if w < 0 else int(w * dp)
     h = h if h < 0 else int(h * dp)
     # No (w,h) constructor
     params = ViewPagerLayoutParams()
     params.width = w
     params.height = h
     params.isDecor = True
     return params