 
 ;; ### Layout parameters attributes
 
-(defn layout-params
+(defn default-layout-params
   "Construct LayoutParams instance from the given arguments. Arguments
-could be either actual values or keywords `:fill` and `:wrap`.
-
-Taken from clj-android by remvee."
+could be either actual values or keywords `:fill` and `:wrap`."
+  ([width height]
+     (let [real-width (attribute-value :layout-params (or width :wrap))
+           real-height (attribute-value :layout-params (or height :wrap))]
+       `(new ~ViewGroup$LayoutParams ~real-width ~real-height))))
+
+(defn linear-layout-params
+  "Construct LinearLayout-specific LayoutParams instance from the
+given arguments. Arguments could be either actual values or keywords
+`:fill` and `:wrap`."
   ([width height weight]
      (let [real-width (attribute-value :layout-params (or width :wrap))
            real-height (attribute-value :layout-params (or height :wrap))
            real-weight (or weight 0)]
-       `(new LinearLayout$LayoutParams ~real-width ~real-height ~real-weight))))
+       `(new ~LinearLayout$LayoutParams
+             ~real-width ~real-height ~real-weight))))
 
 (defmethod transform-attributes :layout-params [el-type obj attributes
-                                                generated-code]
-  [(dissoc attributes :layout-width :layout-height :layout-weight)
-   (conj generated-code
-         `(.setLayoutParams ~obj
-                            ~(layout-params (:layout-width attributes)
-                                            (:layout-height attributes)
-                                            (:layout-weight attributes))))])
+                                                generated-code container-type]
+  (case container-type
+   :linear-layout
+   [(dissoc attributes :layout-width :layout-height :layout-weight)
+    (conj generated-code
+          `(.setLayoutParams ~obj
+             ~(linear-layout-params (:layout-width attributes)
+                                    (:layout-height attributes)
+                                    (:layout-weight attributes))))]
+
+   [(dissoc attributes :layout-width :layout-height :layout-weight)
+    (conj generated-code
+          `(.setLayoutParams ~obj
+             ~(default-layout-params (:layout-width attributes)
+                (:layout-height attributes))))]))
 
 ;; ### Default attributes
 
 ;; If there is no method for the given element type then return
 ;; unmodified `attributes` and `generated-code`.
 ;;
-(defmethod transform-attributes :default [_ _ attributes generated-code]
+(defmethod transform-attributes :default [_1 _2 attributes generated-code _3]
   [attributes generated-code])
 
 (defn default-setters-from-attributes

  "Takes a tree of elements and generates the code to create a new
  element object, set all attributes onto it and add all inside
  elements to it. `make-ui-element` is called recursively on each
  internal element. Presumes the `*context*` var to be bound."
  [[el-type attributes & inside-elements]]
  (let [klass (classname el-type)
        obj (gensym (.getSimpleName klass))]
    `(let [~obj (new ~klass *context*)]
       ~@(process-attributes el-type obj attributes)
       ~@(map (fn [el]
                `(.addView ~obj ~(make-ui-element el)))
              inside-elements)
       ~obj)))

(defmacro defui [tree]
  (make-ui-element tree))

  element's parents, in the end calls
  `default-setters-from-attributes` on what is left from the
  attributes map. Returns the generated code for all attributes."
  [el-type obj attributes container-type]
  (let [[rest-attributes generated-code]
        (reduce (fn [[attrs gen-code] type]
                  (transform-attributes type obj attrs gen-code container-type))
                [attributes ()]
                (conj (all-parents el-type) el-type))]
    (concat generated-code
