   (defn tab-scroll-view-getSelectedTab
     [this]
     (get-state this :selected))
+  (defn tab-scroll-view-animateScroll
+    [this new-scroll]
+    (let [animator (android.animation.ObjectAnimator/ofInt
+                     this "scroll" (.getScrollX this))]
+      (.setDuration animator (get-state this :animation-duration))
+      (.start animator)))
   )
 
 (do
-  (gen-class
-    :name "net.nightweb.tabs.TabView"
-    :extends net.nightweb.LinearLayout
-    :state "state"
-    :init "init"
-    :post-init "post-init"
-    :prefix "tab-view-"
-    :constructors {[android.content.Context] [android.content.Context]
-                   [android.content.Context android.util.AttributeSet] [android.content.Context android.util.AttributeSet]
-                   [android.content.Context android.util.AttributeSet int] [android.content.Context android.util.AttributeSet int]}
-    :methods [["setTitle" [String] void]]
-    :exposes-methods {onLayout superOnLayout
-                      setActivated superSetActivated})
+  (defn tab-layout-create-state
+    [context tabs]
+    (let [res (.getResources context)
+          tab-overlap (.getDimension res (get-resource :dimen :tab_overlap))]
+      (atom {:tab-overlap tab-overlap
+             :tabs tabs})))
+  (defn tab-layout-init
+    ([context tabs] [[context] (tab-layout-create-state context tabs)]))
+  (defn tab-layout-post-init
+    ([this context]
+      (.superSetChildrenDrawingOrderEnabled this true))
+    ([this context attrs] (tab-layout-post-init this context))
+    ([this context attrs def-style] (tab-layout-post-init this context)))
+  (defn tab-layout-onMeasure
+    [this hspec vspec]
+    (.superOnMeasure this hspec vspec)
+    (let [child-count (- (.getChildCount this) 1)
+          max (java.lang.Math/max 0 child-count)
+          tab-overlap (get-state this :tab-overlap)]
+      (.superSetMeasuredDimension this
+                                  (- (.getMeasuredWidth this) (* max tab-overlap))
+                                  (.getMeasuredHeight this))))
+  (defn tab-layout-onLayout
+    [this changed l t r b]
+    (.superOnLayout this changed l t r b)
+    (if (> (.getChildCount this) 0)
+      (for [i (range 1 (.getChildCount this))
+            :let [first-child (.getChildAt this 0)
+                  tab-overlap (get-state this :tab-overlap)
+                  left (- (.getRight first-child) tab-overlap)
+                  total-left (* left i)
+                  tab (.getChildAt this i)
+                  w (- (.getRight tab) (.getLeft tab))]]
+        (.layout tab total-left (.getTop tab) (+ total-left w) (.getBottom tab)))))
+  (defn tab-layout-getChildDrawingOrder
+    [this cnt i]
+    (let [selected (.getSelectedTab (get-state this :tabs))
+          next (- cnt i 1)]
+      (if (and (= i (- cnt 1)) (>= selected 0) (< selected cnt))
+        selected
+        (if (and (<= next selected) (> next 0))
+          (- next 1)
+          next))))
+    )
+
+(do
   (defn tab-view-create-state
     [context]
     (atom {:context context

(defn get-state
  [this mkey]
  (get @(.state this) mkey))

(do
  (gen-class
    :name "net.nightweb.tabs.TabLayout"
    :extends net.nightweb.LinearLayout
    :state "state"
    :init "init"
    :post-init "post-init"
    :prefix "tab-layout-"
    :constructors {[android.content.Context net.nightweb.tabs.TabScrollView] [android.content.Context]}
    :methods []
    :exposes-methods {onMeasure superOnMeasure
                      onLayout superOnLayout})
  (defn tab-layout-create-state
    [context tabs]
    (let [res (.getResources context)
          tab-overlap (.getDimension res (get-resource :dimen :tab_overlap))]
      (atom {:tab-overlap tab-overlap
             :tabs tabs})))
  (defn tab-layout-init
    ([context tabs] [[context] (tab-layout-create-state context tabs)]))
  (defn tab-layout-post-init
    ([this context]
      (.superSetChildrenDrawingOrderEnabled this true)
      )
    ([this context attrs] (tab-layout-post-init this context))
    ([this context attrs def-style] (tab-layout-post-init this context)))
  (defn tab-layout-onMeasure
    [this hspec vspec]
    (.superOnMeasure this hspec vspec)
    (let [child-count (- (.getChildCount this) 1)
          max (java.lang.Math/max 0 child-count)
          tab-overlap (get-state this :tab-overlap)]
      (.superSetMeasuredDimension this
                                  (- (.getMeasuredWidth this) (* max tab-overlap))
                                  (.getMeasuredHeight this))
      ))
  (defn tab-layout-onLayout
    [this changed l t r b]
    (.superOnLayout this changed l t r b)
    (if (> (.getChildCount this) 0)
      (for [i (range 1 (.getChildCount this))
            :let [first-child (.getChildAt this 0)
                  tab-overlap (get-state this :tab-overlap)
                  left (- (.getRight first-child) tab-overlap)
                  total-left (* left i)
                  tab (.getChildAt this i)
                  w (- (.getRight tab) (.getLeft tab))]]
        (.layout tab total-left (.getTop tab) (+ total-left w) (.getBottom tab)))))
  (defn tab-layout-getChildDrawingOrder
    [this cnt i]
    (let [selected (.getSelectedTab (get-state this :tabs))
          next (- cnt i 1)]
      (if (and (= i (- cnt 1)) (>= selected 0) (< selected cnt))
        selected
        (if (and (<= next selected) (> next 0))
          (- next 1)
          next))))
    )

(do
  (gen-class

  (defn tab-bar-onConfigurationChanged
    [this new-config]
    (.superOnConfigurationChanged this new-config)
    (.updateLayout (get-state this :tabs)))
  (defn tab-bar-onMeasure
    [this hspec vspec]
    (.superOnMeasure this hspec vspec)
