Java Code Examples for android.view.ViewGroup#addView()

The following examples show how to use android.view.ViewGroup#addView() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: BlogDemo   File: MainActivity.java    License: Apache License 2.0 6 votes vote down vote up
@NonNull
@Override
public Object instantiateItem(@NonNull ViewGroup container, int position) {
    VpItemView item = null;
    if (position < items.size()){
        item = items.get(position);
    }
    if (item == null){
        item = new VpItemView(MainActivity.this);
        item.setImageUrl(urls.get(position));
        item.setOnImageClick(new VpItemView.OnImageClick() {
            @Override
            public void onClick(SubsamplingScaleImageView imageView) {
                imageView.resetScaleAndCenter();
                viewPager.setVisibility(View.GONE);
            }
        });
    }
    container.addView(item, position);
    return item;
}
 
Example 2
public View buildRecordBig(String valueText, int resourceId, boolean showIcon, boolean isLast,
                           LayoutInflater inflater, ViewGroup container) {
    final View recordView = inflater.inflate(R.layout.contact_record_big, container, false);
    TextView value = (TextView) recordView.findViewById(R.id.value);

    value.setTextColor(style.getTextPrimaryColor());
    value.setText(valueText);

    if (!isLast) {
        recordView.findViewById(R.id.divider).setVisibility(View.GONE);
    }

    if (resourceId != 0 && showIcon) {
        ImageView iconView = (ImageView) recordView.findViewById(R.id.recordIcon);
        Drawable drawable = getResources().getDrawable(resourceId);
        drawable.mutate().setColorFilter(style.getSettingsIconColor(), PorterDuff.Mode.SRC_IN);
        iconView.setImageDrawable(drawable);
    }

    container.addView(recordView);

    return recordView;
}
 
Example 3
private void rebuildUI(Context context) {
    if (!isAdded()) {
        Log.w(TAG, "Cannot build the DashboardSummary UI yet as the Fragment is not added");
        return;
    }

    final long start = System.currentTimeMillis();
    final Resources res = getResources();

    mDashboardContainer.removeAllViews();

    SettingsActivity activity = (SettingsActivity) context;
    List<DashboardCategory> categories = activity.getDashboardCategories(true);

    final int count = categories.size();
    for (int i = 0; i < count; i++) {
        DashboardCategory category = categories.get(i);

        View view = mLayoutInflater.inflate(R.layout.dashboard_category, mDashboardContainer, false);
        TextView labelView = (TextView) view.findViewById(R.id.category_title);
        labelView.setText(category.getTitle(res));
        mDashboardContainer.addView(view);

        ViewGroup categoryContent = (ViewGroup) view.findViewById(R.id.category_content);

        for (DashboardTile tile : category) {
            // Create, fill and add new tile to the category.
            DashboardTileView tileView = (DashboardTileView)
                    mLayoutInflater.inflate(R.layout.dashboard_tile, categoryContent, false);
            tileView.setDashboardTile(tile);
            categoryContent.addView(tileView);
        }
    }

    if (DEBUG) {
        long delta = System.currentTimeMillis() - start;
        Log.d(TAG, "Rebuilding GUI took " + delta + "ms.");
    }
}
 
Example 4
@Override
public Object instantiateItem(ViewGroup collection, int position) {
    final View v;
    if(mRecycled.size() > 0) {
        v = mRecycled.remove(mRecycled.size() - 1);
    } else {
        v = createView(LayoutInflater.from(collection.getContext()), collection, position);
    }
    bindView(v, position);
    collection.addView(v,0);
    return v;
}
 
Example 5
private void setupStatusBarView(Context context, ViewGroup decorViewGroup) {
    mStatusBarTintView = new View(context);
    LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, mConfig.getStatusBarHeight());
    params.gravity = Gravity.TOP;
    if (mNavBarAvailable && !mConfig.isNavigationAtBottom()) {
        params.rightMargin = mConfig.getNavigationBarWidth();
    }
    mStatusBarTintView.setLayoutParams(params);
    mStatusBarTintView.setBackgroundColor(DEFAULT_TINT_COLOR);
    mStatusBarTintView.setVisibility(View.GONE);
    decorViewGroup.addView(mStatusBarTintView);
}
 
Example 6
Source Project: MyHearts   File: TranslucentUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 添加半透明矩形条
 *
 * @param activity       需要设置的 activity
 * @param statusBarAlpha 透明值
 */
private static void addTranslucentView(Activity activity, int statusBarAlpha) {
    ViewGroup contentView = (ViewGroup) activity.findViewById(android.R.id.content);
    if (contentView.getChildCount() > 1) {
        contentView.getChildAt(1).setBackgroundColor(Color.argb(statusBarAlpha, 0, 0, 0));
    } else {
        contentView.addView(createTranslucentStatusBarView(activity, statusBarAlpha));
    }
}
 
Example 7
Source Project: mytracks   File: ChartFragment.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onStart() {
  super.onStart();
  ViewGroup layout = (ViewGroup) getActivity().findViewById(R.id.chart_view_layout);
  LayoutParams layoutParams = new LayoutParams(
      LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
  layout.addView(chartView, layoutParams);
}
 
Example 8
Source Project: SparkleMotion   File: ViewPagerAdapter.java    License: MIT License 5 votes vote down vote up
/**
 * Create the page for the given position.
 *
 * @param container The containing View in which the page will be shown.
 * @param position The page position to be instantiated.
 * @return Returns an Object representing the new page. This does not need
 * to be a View, but can be some other container of the page.
 */
@Override
public final Object instantiateItem(ViewGroup container, int position) {
    final View view = getView(position, container);
    if (view != null) {
        container.addView(view);
    }
    return view;
}
 
Example 9
Source Project: Carbon   File: Snackbar.java    License: Apache License 2.0 5 votes vote down vote up
public void show(final ViewGroup container) {
    synchronized (SnackbarLayout.class) {
        this.container = container;
        if (!next.contains(this))
            next.add(this);
        if (next.indexOf(this) == 0) {
            Rect windowFrame = new Rect();
            container.getWindowVisibleDisplayFrame(windowFrame);
            Rect drawingRect = new Rect();
            container.getDrawingRect(drawingRect);
            //setPaddingBottom(0, 0, 0, drawingRect.bottom - windowFrame.bottom);
            if (style == null)
                setStyle(Style.Auto);
            container.addView(snackbarLayout, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
            snackbarView.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED), View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
            ViewGroup.MarginLayoutParams layoutParams = (ViewGroup.MarginLayoutParams) snackbarView.getLayoutParams();
            if ((gravity & Gravity.BOTTOM) == Gravity.BOTTOM) {
                snackbarView.setTranslationY(snackbarView.getMeasuredHeight() + layoutParams.bottomMargin);
            } else {
                snackbarView.setTranslationY(-snackbarView.getMeasuredHeight() - layoutParams.topMargin);
            }
            snackbarView.setVisibility(INVISIBLE);
            snackbarView.animateVisibility(View.VISIBLE);
            if (duration != INFINITE)
                handler.postDelayed(hideRunnable, duration);
        }
    }
}
 
Example 10
@Override
protected void onAddEditTextToDialogView(@NonNull View dialogView, @NonNull EditText editText) {
    ViewGroup container = dialogView.findViewById(R.id.edittext_container);
    if (container != null) {
        container.addView(editText, ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.WRAP_CONTENT);
    }
}
 
Example 11
Source Project: FABtransitions   File: FloatingActionButton.java    License: MIT License 5 votes vote down vote up
public FloatingActionButton create() {
    final FloatingActionButton button = new FloatingActionButton(activity);
    button.setFloatingActionButtonColor(this.color);
    button.setFloatingActionButtonDrawable(this.drawable);
    params.gravity = this.gravity;
    ViewGroup root = (ViewGroup) activity.findViewById(android.R.id.content);
    root.addView(button, params);

    return button;
}
 
Example 12
private void setupActionBar()
{
    ViewGroup rootView = findViewById(R.id.action_bar_root); //id from appcompat
    if (rootView != null)
    {
        View view = getLayoutInflater().inflate(R.layout.activity_toolbar, rootView, false);
        rootView.addView(view, 0);

        Toolbar toolbar = findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
    }

    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null)
    {
        // Show the Up button in the action bar.
        actionBar.setDisplayHomeAsUpEnabled(true);
        actionBar.setTitle(R.string.action_app_settings);
    }

    // activate toolbar separator, if necessary
    {
        final int sepColor = CompatUtils.getThemeColorAttr(this, R.attr.colorToolBarSeparator);
        if (sepColor != Color.TRANSPARENT && findViewById(R.id.toolbar_separator) != null)
        {
            findViewById(R.id.toolbar_separator).setVisibility(View.VISIBLE);
        }
    }
}
 
Example 13
Source Project: FABtransitions   File: FloatingActionButton.java    License: MIT License 5 votes vote down vote up
public FloatingActionButton create() {
    final FloatingActionButton button = new FloatingActionButton(activity);
    button.setFloatingActionButtonColor(this.color);
    button.setFloatingActionButtonDrawable(this.drawable);
    params.gravity = this.gravity;
    ViewGroup root = (ViewGroup) activity.findViewById(android.R.id.content);
    root.addView(button, params);
    return button;
}
 
Example 14
Source Project: Bitocle   File: ActionBarPullToRefresh.java    License: Apache License 2.0 5 votes vote down vote up
private static void insertLayoutIntoViewGroup(ViewGroup viewGroup,
        PullToRefreshLayout pullToRefreshLayout) {
    // Move all children to PullToRefreshLayout. This code looks a bit silly but the child
    // indices change every time we remove a View (so we can't just iterate through)
    View child = viewGroup.getChildAt(0);
    while (child != null) {
        viewGroup.removeViewAt(0);
        pullToRefreshLayout.addView(child);
        child = viewGroup.getChildAt(0);
    }

    viewGroup.addView(pullToRefreshLayout, ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT);
}
 
Example 15
@Override
    public Object instantiateItem(final ViewGroup container, final int position) {
        View itemView = mLayoutInflater.inflate(R.layout.page_item, container, false);
        ImageView imageView = itemView.findViewById(R.id.imageView);
        imageView.setImageResource(mResources[position]);

        ((TextView) itemView.findViewById(R.id.heading)).setText(context.getString(heading[position]));
        ((TextView) itemView.findViewById(R.id.subheading)).setText(context.getString(subheading[position]));
        if (position == mResources.length - 1) {
            itemView.findViewById(R.id.done).setVisibility(View.VISIBLE);
        } else {
            itemView.findViewById(R.id.done).setVisibility(View.GONE);
        }
//
//        itemView.setOnTouchListener(new View.OnTouchListener() {
//            @Override
//            public boolean onTouch(View v, MotionEvent event) {
//                if (Helper.getViewWidth(v) / 2 < event.getX()) {
//                    if (position != mResources.length) {
//                        mobikulAutoScrollableView.getMyCustomViewPager().setCurrentItem(position + 1);
//                        mobikulAutoScrollableView.getMyCustomViewPager().getAdapter().notifyDataSetChanged();
//                        Log.d(TAG, "onTouch: " + "Right" + mobikulAutoScrollableView.getMyCustomViewPager().getCurrentItem());
//                    }
//                } else {
//                    if (position != 0) {
//                        mobikulAutoScrollableView.getMyCustomViewPager().setCurrentItem(position - 1);
//                        mobikulAutoScrollableView.getMyCustomViewPager().getAdapter().notifyDataSetChanged();
//                        Log.d(TAG, "onTouch: " + "Left" + mobikulAutoScrollableView.getMyCustomViewPager().getCurrentItem());
//                    }
//                }
//                return false;
//            }
//        });

        itemView.findViewById(R.id.done).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                AppSharedPref.setShowWalkThrough(context, true);
                Intent i = new Intent(context, MainActivity.class);
                context.startActivity(i);
                ((WalkthroughActivity) context).finish();
            }
        });

        container.addView(itemView);
        return itemView;
    }
 
Example 16
@Override
public void showInParent(final ViewGroup parentView) {
    removeFromParent();
    parentView.addView(getContainerView());
}
 
Example 17
/**
 * 绑定视图-统计信息
 * 
 * @param cView
 * @param cItem
 */
private void bindStatsView(View cView, HeroDetailItem cItem) {
    if (cItem == null || cItem.stats1 == null
            || cItem.stats1.size() != 6) {
        return;
    }

    final LinearLayout layoutStats1 = Utils.findById(cView, R.id.layout_hero_stats1);
    final LinearLayout layoutStats2 = Utils.findById(cView, R.id.layout_hero_stats2);
    if (layoutStats1 == null || layoutStats2 == null) {
        return;
    }

    final Context context = cView.getContext();
    final Resources res = context.getResources();
    final String[] labels = res.getStringArray(R.array.array_hero_stats);
    final int[] resIds = new int[] {
            R.drawable.overviewicon_int, R.drawable.overviewicon_agi,
            R.drawable.overviewicon_str, R.drawable.overviewicon_attack,
            R.drawable.overviewicon_speed, R.drawable.overviewicon_defense
    };

    final LayoutInflater inflater = LayoutInflater.from(context);
    final int hpIndex = (cItem.hp.equals("intelligence") ? 0
            : (cItem.hp.equals("agility") ? 1 : 2));
    ViewGroup cParent = layoutStats1;
    View view = null;
    TextView text = null;
    ImageView image = null;
    for (int i = 0; i < cItem.stats1.size(); i++) {
        cParent = (i <= 2 ? layoutStats1 : layoutStats2);
        view = inflater.inflate(
                R.layout.fragment_herodetail_stats_list_item, cParent,
                false);

        text = Utils.findById(view, R.id.text_hero_stats_label);
        text.setText(labels[i]);

        image = Utils.findById(view, R.id.image_hero_stats_icon);
        image.setImageResource(resIds[i]);

        text = Utils.findById(view, R.id.text_hero_stats_value);
        text.setText(cItem.stats1.get(i)[2]);
        if (hpIndex == i) {
            image = Utils.findById(view, R.id.image_hero_stats_icon_primary);
            image.setVisibility(View.VISIBLE);
        }
        cParent.addView(view);
    }
}
 
Example 18
private View createView(final Context context, RemoteViews remoteViews, boolean isBig, boolean systemId) {
	if (remoteViews == null)
		return null;
	Context base = mNotificationCompat.getHostContext();
	init(base);
	VLog.v(TAG, "createView:big=" + isBig + ",system=" + systemId);
	// TODO 需要适配
	int height = isBig ? notification_max_height : notification_min_height;

	int width = mWidthCompat.getNotificationWidth(base, notification_panel_width, height,
			notification_side_padding);
	VLog.v(TAG, "createView:getNotificationWidth=" + width);
	ViewGroup frameLayout = new FrameLayout(context);
	VLog.v(TAG, "createView:apply");

	View view1 = apply(context, remoteViews);

	FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
			ViewGroup.LayoutParams.MATCH_PARENT);
	params.gravity = Gravity.CENTER_VERTICAL;
	frameLayout.addView(view1, params);
	if (view1 instanceof ViewGroup) {
		VLog.v(TAG, "createView:fixTextView");
		fixTextView((ViewGroup) view1);
	}
	int mode;
	// TODO 各种适配
	if (systemId) {
		mode = View.MeasureSpec.EXACTLY;
	} else {
		if (isBig) {
			mode = View.MeasureSpec.AT_MOST;
		} else {
			mode = View.MeasureSpec.EXACTLY;
		}
	}
	VLog.v(TAG, "createView:layout");
	View mCache = frameLayout;
	mCache.layout(0, 0, width, height);
	mCache.measure(View.MeasureSpec.makeMeasureSpec(width, View.MeasureSpec.EXACTLY),
			View.MeasureSpec.makeMeasureSpec(height, mode));
	mCache.layout(0, 0, width, mCache.getMeasuredHeight());
	VLog.v(TAG, "notification:systemId=" + systemId + ",max=%d/%d, szie=%d/%d", width, height,
			mCache.getMeasuredWidth(), mCache.getMeasuredHeight());
	return mCache;
}
 
Example 19
Source Project: GuideDialog   File: ItHeiMaDialog.java    License: MIT License 4 votes vote down vote up
@Override
public Object instantiateItem(ViewGroup container, int position) {
    container.addView(pageViews.get(position));
    return pageViews.get(position);
}
 
Example 20
/**
   * 为DrawerLayout 布局设置状态栏变色
   *
   * @param activity 需要设置的activity
   * @param drawerLayout DrawerLayout
   * @param color 状态栏颜色值
   * @param statusBarAlpha 状态栏透明度
   */
  public static void setColorForDrawerLayout(Activity activity, DrawerLayout drawerLayout,
      int color, int statusBarAlpha) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
      return;
    }
    //非miui 非魅族 非6.0以上 需要改变颜色
    if (!Build.MANUFACTURER.equalsIgnoreCase("Meizu") && !Build.MANUFACTURER
        .equalsIgnoreCase("Xiaomi") &&
        Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
      if (ThemeStore.isMDColorLight()) {
        color = ColorUtil.getColor(R.color.accent_gray_color);
      }
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
      activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
      activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
      activity.getWindow().setStatusBarColor(Color.TRANSPARENT);
    } else {
      activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
    }
    // 生成一个状态栏大小的矩形
    // 添加 statusBarView 到布局中
    ViewGroup contentLayout = (ViewGroup) drawerLayout.getChildAt(0);
    if (contentLayout.getChildCount() > 0 && contentLayout.getChildAt(0) instanceof StatusBarView) {
      contentLayout.getChildAt(0).setBackgroundColor(calculateStatusColor(color, statusBarAlpha));
    } else {
      StatusBarView statusBarView = createStatusBarView(activity, color);
      contentLayout.addView(statusBarView, 0);
    }
    // 内容布局不是 LinearLayout 时,设置padding top
    if (!(contentLayout instanceof LinearLayout) && contentLayout.getChildAt(1) != null) {
      contentLayout.getChildAt(1).setPadding(0, getStatusBarHeight(activity), 0, 0);
    }

    // 设置属性
    ViewGroup drawer = (ViewGroup) drawerLayout.getChildAt(1);
    drawerLayout.setFitsSystemWindows(false);
    contentLayout.setFitsSystemWindows(false);
    contentLayout.setClipToPadding(true);
    drawer.setFitsSystemWindows(false);
    // 侧滑添加statusbarView
    LinearLayout headerContainer = drawer.findViewById(R.id.header);
    if (headerContainer != null) {
      headerContainer.addView(createStatusBarView(activity, color), 0);
    }

//        addTranslucentView(activity, statusBarAlpha);

  }