Example usage for android.view ViewGroup addView

List of usage examples for android.view ViewGroup addView

Introduction

In this page you can find the example usage for android.view ViewGroup addView.

Prototype

public void addView(View child) 

Source Link

Document

Adds a child view.

Usage

From source file:Main.java

private static void addDivider(final ViewGroup stripView, final View dividerView) {
    stripView.addView(dividerView);
    final LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) dividerView.getLayoutParams();
    params.gravity = Gravity.CENTER;//from w  w  w . ja v a2s  .com
}

From source file:Main.java

public static void injectViewInLayout(ViewGroup viewGroup, int id) {
    View view = View.inflate(viewGroup.getContext(), id, null);
    view.setId(id);//  w w w. j  a va 2s.co  m
    viewGroup.addView(view);
}

From source file:Main.java

public static void addViewOnly(ViewGroup layout, View view) {
    try {//from   w  ww . j  av  a 2  s.c  o m
        if (layout.getChildCount() > 0) {
            layout.removeAllViews();
        }
        layout.addView(view);
    } catch (Exception e) {
        // e.printStackTrace();
    }
}

From source file:Main.java

public static void addViewOnly(ViewGroup layout, View view) {
    try {//from w  w w  .  j  a v a 2s.c  o m
        if (layout.getChildCount() > 0) {
            layout.removeAllViews();
        }
        layout.addView(view);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:Main.java

private static void addTranslucentView(Activity activity, int statusBarAlpha) {
    ViewGroup contentView = (ViewGroup) activity.findViewById(android.R.id.content);
    if (contentView.getChildCount() > 1) {
        contentView.removeViewAt(1);/*from   ww w.j  av a 2  s.c  o  m*/
    }
    contentView.addView(createTranslucentStatusBarView(activity, statusBarAlpha));
}

From source file:Main.java

public static ViewGroup getPlacer(ViewGroup container) {
    if (NEEDS_FRAME_LAYOUT_HACK) {
        // Insert RelativeLayout to be able to setMargin because pre-Honeycomb FrameLayout
        // could not handle setMargin properly.
        final ViewGroup placer = new RelativeLayout(container.getContext());
        container.addView(placer);
        return placer;
    } else {//from w w  w . jav a  2s . com
        return container;
    }
}

From source file:Main.java

public static void setView(Activity activity, int id) {
    LayoutInflater layoutInflater = LayoutInflater.from(activity);
    setTranslucentStatus(activity);//from   w w w.j  a  v  a  2 s  . co  m
    ViewGroup decorView = (ViewGroup) activity.getWindow().getDecorView().findViewById(android.R.id.content);
    int height = getStatusBarHeight(activity);
    ViewGroup linearLayout = (ViewGroup) layoutInflater.from(activity).inflate(id, null);
    linearLayout.setPadding(0, height, 0, 0);
    decorView.removeAllViews();
    decorView.addView(linearLayout);

}

From source file:com.dm.material.dashboard.candybar.helpers.ViewHelper.java

public static void removeSearchViewSearchIcon(@Nullable View view) {
    if (view != null) {
        ImageView searchIcon = (ImageView) view;
        ViewGroup linearLayoutSearchView = (ViewGroup) view.getParent();
        if (linearLayoutSearchView != null) {
            linearLayoutSearchView.removeView(searchIcon);
            linearLayoutSearchView.addView(searchIcon);

            searchIcon.setAdjustViewBounds(true);
            searchIcon.setMaxWidth(0);//from   ww w . j  av  a 2  s . com
            searchIcon.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
                    LinearLayout.LayoutParams.WRAP_CONTENT));
            searchIcon.setImageDrawable(null);
        }
    }
}

From source file:com.battlelancer.seriesguide.util.PeopleListHelper.java

private static void addShowAllView(LayoutInflater inflater, ViewGroup peopleContainer,
        View.OnClickListener clickListener) {
    TextView showAllView = (TextView) inflater.inflate(R.layout.item_action_add, peopleContainer, false);
    showAllView.setText(R.string.action_display_all);
    showAllView.setOnClickListener(clickListener);
    peopleContainer.addView(showAllView);
}

From source file:com.ofalvai.bpinfo.util.UiUtils.java

/**
 * Adds a rectangular icon for the affected route.
 *
 * First it creates a TextView, then sets the style properties of the view.
 * The custom colored rounded background is achieved by a Drawable and a ColorFilter on top of that.
 *///from  ww  w . ja  v  a 2  s  .c  o m
public static void addRouteIcon(Context context, @NonNull ViewGroup root, @NonNull Route route) {
    ContextThemeWrapper iconContextTheme = new ContextThemeWrapper(context, R.style.RouteIcon);
    TextView iconView = new TextView(iconContextTheme);

    iconView.setText(route.getShortName());
    iconView.setTextColor(route.getTextColor());
    iconView.setContentDescription(Utils.getContentDescriptionForRoute(context, route));
    root.addView(iconView);

    // Layout attributes defined in R.style.RouteIcon were ignored before attaching the view to
    // a parent, so we need to manually set them
    ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) iconView.getLayoutParams();
    params.width = ViewGroup.LayoutParams.WRAP_CONTENT;
    int margin = (int) context.getResources().getDimension(R.dimen.route_icon_margin);
    params.rightMargin = margin;
    params.topMargin = margin;
    // A requestLayout() call is not necessary here because the setBackground() method below
    // will call that anyway.
    //iconView.requestLayout();

    // Setting a custom colored rounded background drawable as background
    Drawable iconBackground = context.getResources().getDrawable(R.drawable.rounded_corner_5dp);
    if (iconBackground != null) {
        ColorFilter colorFilter = new LightingColorFilter(Color.rgb(1, 1, 1), route.getColor());
        iconBackground.mutate().setColorFilter(colorFilter);
        iconView.setBackground(iconBackground);
    }
}