Code example for LinearLayout

Methods: addViewgetChildAtgetChildCountsetOrientation

0
		 
		// check (expected) toast layout 
		if (rootView instanceof LinearLayout) {
			linearLayout = (LinearLayout) rootView;
			 
			if (linearLayout.getChildCount() == 1) {
				View child = linearLayout.getChildAt(0);
				 
				if (child instanceof TextView) {
					messageTextView = (TextView) child;
					 
					if (!(messageTextView.getLayoutParams() instanceof LinearLayout.LayoutParams)) {
						messageTextView = null;
					} 
				} 
			} 
		} 
		 
		// cancel modification because toast layout is not what we expected 
		if (linearLayout == null || messageTextView == null) {
			L.w("failed to create image toast layout, using usual toast"); 
			return toast;
		} 
		 
		ViewGroup.LayoutParams textParams = messageTextView.getLayoutParams();
		((LinearLayout.LayoutParams) textParams).gravity = Gravity.CENTER_VERTICAL;
		 
		// convert dip dimension 
		int imageSize = dipToPixel(context, 25);
		int imageMargin = dipToPixel(context, 15);
		 
		// setup image view layout parameters 
		LinearLayout.LayoutParams imageParams = new LinearLayout.LayoutParams(imageSize, imageSize);
		imageParams.setMargins(0, 0, imageMargin, 0);
		imageParams.gravity = Gravity.CENTER_VERTICAL;
		 
		// setup image view 
		ImageView imageView = new ImageView(context);
		imageView.setImageResource(imageResId);
		imageView.setLayoutParams(imageParams);
		 
		// modify root layout 
		linearLayout.setOrientation(LinearLayout.HORIZONTAL);
		linearLayout.addView(imageView, 0);
		 
		return toast;
	}