Example usage for android.widget LinearLayout LinearLayout

List of usage examples for android.widget LinearLayout LinearLayout

Introduction

In this page you can find the example usage for android.widget LinearLayout LinearLayout.

Prototype

public LinearLayout(Context context) 

Source Link

Usage

From source file:com.digi.android.wva.fragments.ChartFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Add chart view to container
    if (container == null) {
        container = new LinearLayout(getActivity());
    }/*from   ww  w.j a v a  2  s  .  com*/
    container.addView(ChartFactory.getCombinedXYChartView(getActivity(), mDataset, mRenderer,
            new String[] { LineChart.TYPE, LineChart.TYPE }));
    return container;
}

From source file:it.redturtle.mobile.apparpav.MeteogramAdapter.java

/**
 * SINGLE IMAGE ROW//from   www .j a  va 2s  .  com
 * @param att
 * @param linear
 * @return
 */
public LinearLayout getSingleImageRow(Map<String, String> att, LinearLayout linear) {

    LinearLayout container_layout = new LinearLayout(context);
    container_layout.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.view_shape_meteo));
    container_layout.setMinimumHeight(46);
    container_layout.setVerticalGravity(Gravity.CENTER);

    LinearLayout.LayoutParams value = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
            LayoutParams.WRAP_CONTENT, 0.5f);
    TextView tx = new TextView(context);
    tx.setText(att.get("title"));
    tx.setTextSize(11);
    tx.setTypeface(null, Typeface.BOLD);
    tx.setGravity(Gravity.LEFT);
    tx.setPadding(3, 0, 0, 2);
    tx.setTextColor(Color.rgb(66, 66, 66));
    container_layout.addView(tx, value);

    LinearLayout.LayoutParams value_params = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, 40, 0.5f);
    ImageView img = new ImageView(context);
    String path = "it.redturtle.mobile.apparpav:drawable/" + FilenameUtils.removeExtension(att.get("value"));
    img.setImageResource(context.getResources().getIdentifier(path, null, null));
    img.setPadding(0, 3, 0, 3);
    container_layout.addView(img, value_params);

    linear.addView(container_layout);
    return linear;
}

From source file:com.achep.header2actionbar.HeaderFragmentSupportV4.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final Activity activity = getActivity();
    assert activity != null;
    mFrameLayout = new FrameLayout(activity);

    mHeader = onCreateHeaderView(inflater, mFrameLayout);
    mHeaderHeader = mHeader.findViewById(android.R.id.title);
    mHeaderBackground = mHeader.findViewById(android.R.id.background);
    assert mHeader.getLayoutParams() != null;
    mHeader.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED),
            View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
    mHeaderHeight = mHeader.getMeasuredHeight();

    mFakeHeader = new Space(activity);

    View content = onCreateContentView(inflater, mFrameLayout);
    mContentView = content;/* w  w  w .  j ava 2  s . c o m*/
    Log.i(TAG, "container:" + container.getMeasuredHeight() + ",mHeaderHeight=" + mHeaderHeight);

    final View topContentView = container;

    if (content instanceof ListView) {
        isListViewEmpty = true;

        final ListView listView = (ListView) content;
        mFakeHeader.setLayoutParams(new ListView.LayoutParams(0, mHeaderHeight));
        listView.addHeaderView(mFakeHeader);
        listView.setOnScrollListener(new AbsListView.OnScrollListener() {

            @Override
            public void onScrollStateChanged(AbsListView absListView, int scrollState) {
                if (mOnScrollListener != null) {
                    mOnScrollListener.onScrollStateChanged(absListView, scrollState);
                }
            }

            @Override
            public void onScroll(AbsListView absListView, int firstVisibleItem, int visibleItemCount,
                    int totalItemCount) {
                if (isListViewEmpty) {
                    scrollHeaderTo(0);
                } else {
                    final View child = absListView.getChildAt(0);
                    assert child != null;
                    scrollHeaderTo(child == mFakeHeader ? child.getTop() : -mHeaderHeight);
                }
            }
        });
    } else {
        topContentView.getViewTreeObserver()
                .addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
                    @SuppressWarnings("deprecation")
                    @Override
                    public void onGlobalLayout() {
                        //Remove it here unless you want to get this callback for EVERY
                        //layout pass, which can get you into infinite loops if you ever
                        //modify the layout from within this method.
                        topContentView.getViewTreeObserver().removeGlobalOnLayoutListener(this);

                        //Now you can get the width and height from content
                        int actionBarHeight = 0;
                        TypedValue tv = new TypedValue();
                        if (getActivity().getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) {
                            actionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data,
                                    getResources().getDisplayMetrics());
                        }
                        Log.i(TAG, "topContentView:" + topContentView.getHeight() + ", actionBarHeight:"
                                + actionBarHeight + ", getStatusBarHeight:" + getStatusBarHeight());
                        ViewGroup.LayoutParams lp = mContentView.getLayoutParams();
                        lp.height = topContentView.getHeight() - actionBarHeight - getStatusBarHeight();
                        mContentView.setLayoutParams(lp);
                    }
                });

        // Merge fake header view and content view.
        final LinearLayout view = new LinearLayout(activity);
        view.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT));
        view.setOrientation(LinearLayout.VERTICAL);
        mFakeHeader.setLayoutParams(new LinearLayout.LayoutParams(0, mHeaderHeight));
        view.addView(mFakeHeader);
        view.addView(content);

        // Put merged content to ScrollView
        final NotifyingScrollView scrollView = new NotifyingScrollView(activity);
        scrollView.addView(view);
        scrollView.setVerticalScrollBarEnabled(false);
        scrollView.setOverScrollMode(ScrollView.OVER_SCROLL_NEVER);
        scrollView.setOnScrollChangedListener(new NotifyingScrollView.OnScrollChangedListener() {
            @Override
            public void onScrollChanged(ScrollView who, int l, int t, int oldl, int oldt) {
                Log.i(TAG, "onScrollChanged scroll ot -t :" + (-t));
                scrollHeaderTo(-t);
            }
        });
        mContentWrapper = scrollView;
        content = scrollView;
    }

    mFrameLayout.addView(content);
    mFrameLayout.addView(mHeader);

    // Content overlay view always shows at the top of content.
    if ((mContentOverlay = onCreateContentOverlayView(inflater, mFrameLayout)) != null) {
        mFrameLayout.addView(mContentOverlay, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT));
    }

    // Post initial scroll
    mFrameLayout.post(new Runnable() {
        @Override
        public void run() {
            Log.i(TAG, "post initial scroll to 0");
            // SEAN: walk around for scroll position bug
            if (mContentWrapper != null) {
                mContentWrapper.scrollTo(0, 0);
            }
            scrollHeaderTo(0, true);
        }
    });

    return mFrameLayout;
}

From source file:com.eccyan.widget.SpinningTabStrip.java

public SpinningTabStrip(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    setFillViewport(true);/* w w  w.j  av  a  2s .co m*/
    setWillNotDraw(false);
    tabsContainer = new LinearLayout(context);
    tabsContainer.setOrientation(LinearLayout.HORIZONTAL);
    tabsContainer.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
    addView(tabsContainer);

    flingVelocity = new Scroller(getContext());
    flinger = new Flinger();
    gestureDetector = new GestureDetector(getContext(), new GestureDetector.SimpleOnGestureListener() {
        @Override
        public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {

            flingVelocity.forceFinished(true);
            flingVelocity.fling(getScrollX(), getScrollY(), -(int) velocityX, -(int) velocityY,
                    Integer.MIN_VALUE, Integer.MAX_VALUE, 0, getHeight());

            scrollStopped.set(false);
            Log.d(TAG, "scroll fling started");

            return true;
        }

        @Override
        public boolean onDown(MotionEvent e) {
            if (!flingVelocity.isFinished()) {
                flingVelocity.forceFinished(true);
            }

            if (!flinger.isFinished()) {
                flinger.forceFinished(true);
            }

            return super.onDown(e);
        }
    });

    DisplayMetrics dm = getResources().getDisplayMetrics();
    scrollOffset = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, scrollOffset, dm);
    indicatorHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, indicatorHeight, dm);
    underlineHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, underlineHeight, dm);
    dividerPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dividerPadding, dm);
    tabPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, tabPadding, dm);
    dividerWidth = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dividerWidth, dm);
    tabTextSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, tabTextSize, dm);

    // get system attrs (android:textSize and android:textColor)
    TypedArray a = context.obtainStyledAttributes(attrs, ATTRS);
    tabTextSize = a.getDimensionPixelSize(TEXT_SIZE_INDEX, tabTextSize);
    ColorStateList colorStateList = a.getColorStateList(TEXT_COLOR_INDEX);
    int textPrimaryColor = a.getColor(TEXT_COLOR_PRIMARY, android.R.color.white);
    if (colorStateList != null) {
        tabTextColor = colorStateList;
    } else {
        tabTextColor = getColorStateList(textPrimaryColor);
    }

    underlineColor = textPrimaryColor;
    dividerColor = textPrimaryColor;
    indicatorColor = textPrimaryColor;

    // get custom attrs
    a = context.obtainStyledAttributes(attrs, R.styleable.SpinningTabStrip);
    indicatorColor = a.getColor(R.styleable.SpinningTabStrip_pstsIndicatorColor, indicatorColor);
    underlineColor = a.getColor(R.styleable.SpinningTabStrip_pstsUnderlineColor, underlineColor);
    dividerColor = a.getColor(R.styleable.SpinningTabStrip_pstsDividerColor, dividerColor);
    dividerWidth = a.getDimensionPixelSize(R.styleable.SpinningTabStrip_pstsDividerWidth, dividerWidth);
    indicatorHeight = a.getDimensionPixelSize(R.styleable.SpinningTabStrip_pstsIndicatorHeight,
            indicatorHeight);
    underlineHeight = a.getDimensionPixelSize(R.styleable.SpinningTabStrip_pstsUnderlineHeight,
            underlineHeight);
    dividerPadding = a.getDimensionPixelSize(R.styleable.SpinningTabStrip_pstsDividerPadding, dividerPadding);
    tabPadding = a.getDimensionPixelSize(R.styleable.SpinningTabStrip_pstsTabPaddingLeftRight, tabPadding);
    tabBackgroundResId = a.getResourceId(R.styleable.SpinningTabStrip_pstsTabBackground, tabBackgroundResId);
    shouldExpand = a.getBoolean(R.styleable.SpinningTabStrip_pstsShouldExpand, shouldExpand);
    scrollOffset = a.getDimensionPixelSize(R.styleable.SpinningTabStrip_pstsScrollOffset, scrollOffset);
    textAllCaps = a.getBoolean(R.styleable.SpinningTabStrip_pstsTextAllCaps, textAllCaps);
    tabTypefaceStyle = a.getInt(R.styleable.SpinningTabStrip_pstsTextStyle, Typeface.BOLD);
    tabTypefaceSelectedStyle = a.getInt(R.styleable.SpinningTabStrip_pstsTextSelectedStyle, Typeface.BOLD);
    tabTextAlpha = a.getFloat(R.styleable.SpinningTabStrip_pstsTextAlpha, HALF_TRANSP);
    tabTextSelectedAlpha = a.getFloat(R.styleable.SpinningTabStrip_pstsTextSelectedAlpha, OPAQUE);

    a.recycle();

    setMarginBottomTabContainer();

    rectPaint = new Paint();
    rectPaint.setAntiAlias(true);
    rectPaint.setStyle(Style.FILL);

    dividerPaint = new Paint();
    dividerPaint.setAntiAlias(true);
    dividerPaint.setStrokeWidth(dividerWidth);

    defaultTabLayoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.MATCH_PARENT);
    expandedTabLayoutParams = new LinearLayout.LayoutParams(0, LayoutParams.MATCH_PARENT, 1.0f);

    if (locale == null) {
        locale = getResources().getConfiguration().locale;
    }

}

From source file:cn.liucl.stationarytabstrip.PagerSlidingTabStrip.java

private void initContainerView(Context context) {

    //??//from  w  ww . j  ava 2s .c  om
    bodyContainer = new HorScrollView(context);
    bodyContainer.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT));
    bodyContainer.setFillViewport(true);

    //???
    headsContainer = new LinearLayout(context);
    headsContainer.setOrientation(LinearLayout.HORIZONTAL);
    headsContainer.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT));

    tabsContainer = new LinearLayout(context);
    tabsContainer.setOrientation(LinearLayout.HORIZONTAL);
    tabsContainer.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT));
    bodyContainer.addView(tabsContainer);

    //?
    setOrientation(LinearLayout.HORIZONTAL);
    addView(headsContainer);
    addView(bodyContainer);

    bodyContainer.setScrollViewListener(new ScrollListener());
}

From source file:com.farmerbb.taskbar.service.DashboardService.java

@SuppressLint("RtlHardcoded")
private void drawDashboard() {
    windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);

    final WindowManager.LayoutParams params = new WindowManager.LayoutParams(
            WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT,
            WindowManager.LayoutParams.TYPE_PHONE,
            WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
            PixelFormat.TRANSLUCENT);/*www .  j  a  v  a2s.  c  o  m*/

    // Initialize views
    layout = new LinearLayout(this);
    layout.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));
    layout.setVisibility(View.GONE);
    layout.setAlpha(0);

    SharedPreferences pref = U.getSharedPreferences(this);
    int width = pref.getInt("dashboard_width",
            getApplicationContext().getResources().getInteger(R.integer.dashboard_width));
    int height = pref.getInt("dashboard_height",
            getApplicationContext().getResources().getInteger(R.integer.dashboard_height));

    boolean isPortrait = getApplicationContext().getResources()
            .getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT;
    boolean isLandscape = getApplicationContext().getResources()
            .getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE;

    if (isPortrait) {
        columns = height;
        rows = width;
    }

    if (isLandscape) {
        columns = width;
        rows = height;
    }

    maxSize = columns * rows;

    int backgroundTint = U.getBackgroundTint(this);
    int accentColor = U.getAccentColor(this);
    int accentColorAlt = accentColor;
    accentColorAlt = ColorUtils.setAlphaComponent(accentColorAlt, Color.alpha(accentColorAlt) / 2);

    int cellCount = 0;

    for (int i = 0; i < columns; i++) {
        LinearLayout layout2 = new LinearLayout(this);
        layout2.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT, 1));
        layout2.setOrientation(LinearLayout.VERTICAL);

        for (int j = 0; j < rows; j++) {
            DashboardCell cellLayout = (DashboardCell) View.inflate(this, R.layout.dashboard, null);
            cellLayout.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                    ViewGroup.LayoutParams.MATCH_PARENT, 1));
            cellLayout.setBackgroundColor(backgroundTint);
            cellLayout.setOnClickListener(cellOcl);
            cellLayout.setOnHoverListener(cellOhl);

            TextView empty = (TextView) cellLayout.findViewById(R.id.empty);
            empty.setBackgroundColor(accentColorAlt);
            empty.setTextColor(accentColor);

            Bundle bundle = new Bundle();
            bundle.putInt("cellId", cellCount);

            cellLayout.setTag(bundle);
            cells.put(cellCount, cellLayout);
            cellCount++;

            layout2.addView(cellLayout);
        }

        layout.addView(layout2);
    }

    mAppWidgetManager = AppWidgetManager.getInstance(this);
    mAppWidgetHost = new AppWidgetHost(this, APPWIDGET_HOST_ID);
    mAppWidgetHost.startListening();

    for (int i = 0; i < maxSize; i++) {
        int appWidgetId = pref.getInt("dashboard_widget_" + Integer.toString(i), -1);
        if (appWidgetId != -1)
            addWidget(appWidgetId, i, false);
        else if (pref.getBoolean("dashboard_widget_" + Integer.toString(i) + "_placeholder", false))
            addPlaceholder(i);
    }

    mAppWidgetHost.stopListening();

    LocalBroadcastManager.getInstance(this).unregisterReceiver(toggleReceiver);
    LocalBroadcastManager.getInstance(this).unregisterReceiver(addWidgetReceiver);
    LocalBroadcastManager.getInstance(this).unregisterReceiver(removeWidgetReceiver);
    LocalBroadcastManager.getInstance(this).unregisterReceiver(hideReceiver);

    LocalBroadcastManager.getInstance(this).registerReceiver(toggleReceiver,
            new IntentFilter("com.farmerbb.taskbar.TOGGLE_DASHBOARD"));
    LocalBroadcastManager.getInstance(this).registerReceiver(addWidgetReceiver,
            new IntentFilter("com.farmerbb.taskbar.ADD_WIDGET_COMPLETED"));
    LocalBroadcastManager.getInstance(this).registerReceiver(removeWidgetReceiver,
            new IntentFilter("com.farmerbb.taskbar.REMOVE_WIDGET_COMPLETED"));
    LocalBroadcastManager.getInstance(this).registerReceiver(hideReceiver,
            new IntentFilter("com.farmerbb.taskbar.HIDE_DASHBOARD"));

    windowManager.addView(layout, params);

    new Handler().postDelayed(() -> {
        int paddingSize = getResources().getDimensionPixelSize(R.dimen.icon_size);

        switch (U.getTaskbarPosition(DashboardService.this)) {
        case "top_vertical_left":
        case "bottom_vertical_left":
            layout.setPadding(paddingSize, 0, 0, 0);
            break;
        case "top_left":
        case "top_right":
            layout.setPadding(0, paddingSize, 0, 0);
            break;
        case "top_vertical_right":
        case "bottom_vertical_right":
            layout.setPadding(0, 0, paddingSize, 0);
            break;
        case "bottom_left":
        case "bottom_right":
            layout.setPadding(0, 0, 0, paddingSize);
            break;
        }
    }, 100);
}

From source file:com.cc.custom.uikit.PagerSlidingTabStrip.java

public PagerSlidingTabStrip(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    setFillViewport(true);/*w w w.  ja v  a  2  s.c o m*/
    setWillNotDraw(false);

    DisplayMetrics dm = getResources().getDisplayMetrics();

    scrollOffset = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, scrollOffset, dm);
    indicatorHeight = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, indicatorHeight, dm);
    underlineHeight = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, underlineHeight, dm);
    dividerPadding = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dividerPadding, dm);
    indicatorPadding = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, indicatorPadding, dm);
    tabPadding = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, tabPadding, dm);
    dividerWidth = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dividerWidth, dm);
    tabTextSize = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, tabTextSize, dm);

    // get custom attrs

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.PagerSlidingTabStrip);

    indicatorColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsIndicatorColor, indicatorColor);
    underlineColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsUnderlineColor, underlineColor);
    dividerColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsDividerColor, dividerColor);
    tabTextColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsTabTextColor, tabTextColor);
    tabSelectedTextColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsTabSelectedTextColor,
            tabSelectedTextColor);
    tabTextSize = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsTabTextSize, (int) tabTextSize);
    indicatorHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsIndicatorHeight,
            (int) indicatorHeight);
    underlineHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsUnderlineHeight,
            (int) underlineHeight);
    dividerPadding = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsDividerPadding,
            (int) dividerPadding);
    indicatorPadding = a.getDimensionPixelOffset(R.styleable.PagerSlidingTabStrip_pstIndicatorPadding,
            (int) indicatorPadding);
    tabPadding = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsTabPaddingLeftRight,
            (int) tabPadding);
    tabBackgroundResId = a.getResourceId(R.styleable.PagerSlidingTabStrip_pstsTabBackground,
            tabBackgroundResId);
    tabSelectedBackgroundResId = a.getResourceId(R.styleable.PagerSlidingTabStrip_pstsTabSelectedBackgrground,
            tabSelectedBackgroundResId);
    shouldExpand = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsShouldExpand, shouldExpand);
    scrollOffset = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsScrollOffset,
            (int) scrollOffset);
    textAllCaps = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsTextAllCaps, textAllCaps);

    a.recycle();

    tabsContainer = new LinearLayout(context);
    tabsContainer.setOrientation(LinearLayout.HORIZONTAL);
    tabsContainer.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
    addView(tabsContainer);

    rectPaint = new Paint();
    rectPaint.setAntiAlias(true);
    rectPaint.setStyle(Style.FILL);

    dividerPaint = new Paint();
    dividerPaint.setAntiAlias(true);
    dividerPaint.setStrokeWidth(dividerWidth);

    defaultTabLayoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.MATCH_PARENT);
    expandedTabLayoutParams = new LinearLayout.LayoutParams(0, LayoutParams.MATCH_PARENT, 1.0f);

    if (locale == null) {
        locale = getResources().getConfiguration().locale;
    }
}

From source file:com.gome.haoyuangong.views.MyViewPageIndicator.java

private void addTab(int index, CharSequence text, int iconResId) {
    final TabView tabView = new TabView(getContext());
    tabView.mIndex = index;/*from  w ww. jav  a 2 s . com*/
    tabView.setTag("tavView");
    tabView.setId(index);
    //      tabView.setFocusable(true);
    //      tabView.setOnClickListener(mTabClickListener);
    tabView.setText(text);
    //tabView.setPadding(pointSize, 0, pointSize, 0);
    tabView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
    tabView.setMaxLines(1);
    tabView.setGravity(Gravity.CENTER);
    XmlPullParser xrp = getResources().getXml(R.drawable.tab_button);
    try {
        ColorStateList csl = ColorStateList.createFromXml(getResources(), xrp);
        tabView.setTextColor(csl);
    } catch (Exception e) {

    }

    if (iconResId != 0) {
        //tabView.setCompoundDrawablesWithIntrinsicBounds(iconResId, 0, 0, 0);
    }

    FrameLayout.LayoutParams tabTvL = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    tabView.setLayoutParams(tabTvL);

    //measureView(tabView);

    LinearLayout layoutWraper1 = new LinearLayout(getContext());
    LinearLayout.LayoutParams lp1 = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT, 1);
    layoutWraper1.setLayoutParams(lp1);
    layoutWraper1.setGravity(Gravity.CENTER);
    layoutWraper1.setFocusable(true);
    layoutWraper1.setOnClickListener(mTabClickListener);
    layoutWraper1.setPadding(0, 0, 0, 0);
    layoutWraper1.setBackgroundResource(R.drawable.tab_btn_red);

    FrameLayout frameLayout = new FrameLayout(getContext());
    frameLayout.setTag("framelayout");
    //      FrameLayout.LayoutParams fl2 = new FrameLayout.LayoutParams(tabView.getMeasuredWidth() + padding, tabView.getMeasuredHeight()+ (int)(padding * 1.5));
    FrameLayout.LayoutParams fl2 = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    //      frameLayout.setPadding(padding, padding, padding, padding);
    frameLayout.setLayoutParams(fl2);
    //      frameLayout.addView(tabView);

    View hasNew = new View(getContext());
    FrameLayout.LayoutParams hasNewL = new FrameLayout.LayoutParams(pointSize, pointSize);
    hasNew.setLayoutParams(hasNewL);
    hasNewL.gravity = Gravity.TOP | Gravity.RIGHT;
    hasNew.setBackgroundResource(R.drawable.shape_circle);

    FrameLayout tabTvframe = new FrameLayout(getContext());
    FrameLayout.LayoutParams tabTvframeL = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    tabTvframeL.gravity = Gravity.CENTER;
    tabTvframe.setLayoutParams(tabTvframeL);
    tabTvframe.addView(tabView);
    tabTvframe.addView(hasNew);
    hasNew.setVisibility(View.GONE);

    frameLayout.addView(tabTvframe);

    layoutWraper1.addView(frameLayout);

    tabView.setTagView(hasNew);

    mTabLayout.addView(layoutWraper1, new LinearLayout.LayoutParams(0, MATCH_PARENT, 1));
}

From source file:com.hichinaschool.flashcards.anki.multimediacard.activity.MultimediaCardEditorActivity.java

/**
 * Creates a TabBar in case action bar is not present as well as other UI Elements
 *///from  ww w .j  a  v a  2 s  . c o  m
private void initUI() {
    int currentapiVersion = android.os.Build.VERSION.SDK_INT;
    if (currentapiVersion <= android.os.Build.VERSION_CODES.GINGERBREAD_MR1) {
        LinearLayout linearLayout = (LinearLayout) findViewById(R.id.LinearLayoutForSpareMenu);
        createSpareMenu(linearLayout);
    }

    mEditorLayout = (LinearLayout) findViewById(R.id.LinearLayoutInScrollView);

    LinearLayout mToolsLayout = (LinearLayout) findViewById(R.id.LinearLayoutForButtons);

    LayoutParams pars = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT, 1);

    Button swapButton = new Button(this);
    swapButton.setText(gtxt(R.string.multimedia_editor_activity_swap_button));
    mToolsLayout.addView(swapButton, pars);
    swapButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            swap();
        }
    });

    LinearLayout mButtonsLayout = new LinearLayout(this);
    mButtonsLayout.setOrientation(LinearLayout.HORIZONTAL);
    mToolsLayout.addView(mButtonsLayout, pars);

    pars = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 1);

    // DEPRECATED< BUT USED IN THE PROJECT.
    mModelButton = new Button(this);
    mModelButton.setOnClickListener(new OnClickListener() {
        @SuppressWarnings("deprecation")
        @Override
        public void onClick(View v) {
            showDialog(DIALOG_MODEL_SELECT);
        }
    });
    mButtonsLayout.addView(mModelButton, pars);

    mDeckButton = new Button(this);
    mDeckButton.setOnClickListener(new OnClickListener() {
        @SuppressWarnings("deprecation")
        @Override
        public void onClick(View v) {
            showDialog(DIALOG_DECK_SELECT);
        }
    });
    mButtonsLayout.addView(mDeckButton, pars);
}