Advertisement
Guest User

Untitled

a guest
Feb 28th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Haxe 1.73 KB | None | 0 0
  1. class TabPane extends RelativeLayout {
  2.     private var _tabHost:TabHost;
  3.     private var _tabLayout:LinearLayout;
  4.     private var _tabWidget:TabWidget;
  5.     private var _tabContent:FrameLayout;
  6.    
  7.     public function new(context:Context) {
  8.         super(context);
  9.        
  10.         _tabHost = new TabHost(context, null);
  11.         addView(_tabHost, new RelativeLayout_LayoutParams(ViewGroup_LayoutParams.MATCH_PARENT, ViewGroup_LayoutParams.MATCH_PARENT));
  12.        
  13.         _tabLayout = new LinearLayout(context);
  14.         _tabLayout.setOrientation(LinearLayout.VERTICAL);
  15.         _tabHost.addView(_tabLayout, new RelativeLayout_LayoutParams(ViewGroup_LayoutParams.MATCH_PARENT, ViewGroup_LayoutParams.MATCH_PARENT));
  16.        
  17.         _tabWidget = new TabWidget(context);
  18.         _tabWidget.setId(android.R.R_id.tabs);
  19.         _tabLayout.addView(_tabWidget, new LinearLayout_LayoutParams(ViewGroup_LayoutParams.MATCH_PARENT, ViewGroup_LayoutParams.WRAP_CONTENT));
  20.        
  21.         _tabContent = new FrameLayout(context);
  22.         _tabContent.setId(android.R.R_id.tabcontent);
  23.         _tabLayout.addView(_tabContent, new LinearLayout_LayoutParams(ViewGroup_LayoutParams.MATCH_PARENT, ViewGroup_LayoutParams.MATCH_PARENT));
  24.        
  25.         _tabHost.setup();
  26.     }
  27.    
  28.     public function addTab(text:String, view:View) {
  29.         var tabSpec = _tabHost.newTabSpec(text);
  30.         tabSpec.setIndicator(text);
  31.         if (view.getId() == -1) { // could be done better
  32.             view.setId(Std.random(0xFFFFFF));
  33.         }
  34.         _tabContent.addView(view, new FrameLayout_LayoutParams(ViewGroup_LayoutParams.WRAP_CONTENT, ViewGroup_LayoutParams.WRAP_CONTENT));
  35.         tabSpec.setContent(view.getId());
  36.         _tabHost.addTab(tabSpec);
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement