Java Code Examples for android.widget.RelativeLayout#addView()
The following examples show how to use
android.widget.RelativeLayout#addView() .
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 File: BillingActivity.java From AndroidInAppPurchase with Apache License 2.0 | 6 votes |
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //> make a nice spinning circle in the center of the screen ProgressBar progress = new ProgressBar(this, null, android.R.attr.progressBarStyleLarge); RelativeLayout layout = new RelativeLayout(this); RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); params.addRule(RelativeLayout.CENTER_IN_PARENT); layout.addView(progress, params); setContentView(layout); //< Billing.getInstance().purchase(this); }
Example 2
Source File: RSSFeedActivity.java From journaldev with MIT License | 6 votes |
@Override protected void onPreExecute() { super.onPreExecute(); pDialog = new ProgressBar(RSSFeedActivity.this, null, android.R.attr.progressBarStyleLarge); RelativeLayout relativeLayout = findViewById(R.id.relativeLayout); RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT ); lp.addRule(RelativeLayout.CENTER_IN_PARENT); pDialog.setLayoutParams(lp); pDialog.setVisibility(View.VISIBLE); relativeLayout.addView(pDialog); }
Example 3
Source File: MainFragment.java From duo-navigation-drawer with Apache License 2.0 | 6 votes |
@Override public Object instantiateItem(ViewGroup container, int position) { // Create some layout params RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); layoutParams.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE); // Create some text TextView textView = getTextView(container.getContext()); textView.setText(String.valueOf(position)); textView.setLayoutParams(layoutParams); RelativeLayout layout = new RelativeLayout(container.getContext()); layout.setBackgroundColor(ContextCompat.getColor(container.getContext(), R.color.colorPrimary)); layout.setLayoutParams(layoutParams); layout.addView(textView); container.addView(layout); return layout; }
Example 4
Source File: PLManager.java From panoramagl with Apache License 2.0 | 6 votes |
/** * This event is fired when GLSurfaceView is created * * @param glSurfaceView current GLSurfaceView */ @SuppressWarnings("deprecation") protected View onGLSurfaceViewCreated(GLSurfaceView glSurfaceView) { for (int i = 0; i < kMaxTouches; i++) mInternalTouches.add(new UITouch(glSurfaceView, new CGPoint(0.0f, 0.0f))); mContentLayout = new RelativeLayout(context); mContentLayout.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); mContentLayout.addView(glSurfaceView, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); LayoutParams progressBarLayoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); progressBarLayoutParams.addRule(RelativeLayout.CENTER_IN_PARENT); mProgressBar = new ProgressBar(context); mProgressBar.setIndeterminate(true); mProgressBar.setVisibility(View.GONE); mContentLayout.addView(mProgressBar, progressBarLayoutParams); return this.onContentViewCreated(mContentLayout); }
Example 5
Source File: HintCaseView.java From hintcase with Apache License 2.0 | 6 votes |
private void setViews() { if (existHintBlock()) { FrameLayout frameLayout = getHintBlockFrameLayout(); if (hintBlockView == NO_BLOCK_INFO_VIEW) { hintBlockView = hintBlock.getView(getContext(), hintCase, frameLayout); hintBlockView.setAlpha(0); } frameLayout.addView(hintBlockView); addView(frameLayout); } if (existExtraBlock()) { RelativeLayout relativeLayout = getExtraContentHolderRelativeLayout(); for (int i = 0; i < extraBlocks.size(); i++) { View view = extraBlocks.get(i).getView(getContext(), hintCase, relativeLayout); if (showExtraContentHolderAnimators.get(i) != ContentHolderAnimator.NO_ANIMATOR) { view.setAlpha(0); } extraBlockViews.add(view); relativeLayout.addView(view); } addView(relativeLayout); } }
Example 6
Source File: EditPagePort.java From YiZhi with Apache License 2.0 | 5 votes |
public void onCreate() { super.onCreate(); int screenHeight = ResHelper.getScreenHeight(activity); float ratio = ((float) screenHeight) / DESIGN_SCREEN_HEIGHT; maxBodyHeight = 0; llPage = new LinearLayout(activity); llPage.setOrientation(LinearLayout.VERTICAL); activity.setContentView(llPage); rlTitle = new RelativeLayout(activity); rlTitle.setBackgroundColor(0xffe6e9ec); int titleHeight = (int) (DESIGN_TITLE_HEIGHT * ratio); LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, titleHeight); llPage.addView(rlTitle, lp); initTitle(rlTitle, ratio); RelativeLayout rlBody = new RelativeLayout(activity); rlBody.setBackgroundColor(0xffffffff); lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); llPage.addView(rlBody, lp); initBody(rlBody, ratio); LinearLayout llShadow = new LinearLayout(activity); llShadow.setOrientation(LinearLayout.VERTICAL); rlBody.addView(llShadow, new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); initShadow(llShadow, ratio); llBottom = new LinearLayout(activity); llBottom.setOrientation(LinearLayout.VERTICAL); lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); llPage.addView(llBottom, lp); initBottom(llBottom, ratio); }
Example 7
Source File: ColorPickerDialog.java From redalert-android with Apache License 2.0 | 5 votes |
public ColorPickerDialog(Context context, int initialColor, final OnColorSelectedListener onColorSelectedListener) { super(context); RelativeLayout relativeLayout = new RelativeLayout(context); LayoutParams layoutParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); layoutParams.addRule(RelativeLayout.CENTER_IN_PARENT); colorPickerView = new ColorPicker(context); colorPickerView.setColor(initialColor); relativeLayout.addView(colorPickerView, layoutParams); OnClickListener onClickListener = new OnClickListener() { public void onClick(DialogInterface dialog, int which) { switch (which) { case BUTTON_POSITIVE: int selectedColor = colorPickerView.getColor(); onColorSelectedListener.onColorSelected(selectedColor); break; case BUTTON_NEGATIVE: dialog.dismiss(); break; } } }; setButton(BUTTON_POSITIVE, context.getString(android.R.string.ok), onClickListener); setButton(BUTTON_NEGATIVE, context.getString(android.R.string.cancel), onClickListener); setView(relativeLayout); }
Example 8
Source File: BubbleActivity.java From coursera-android with MIT License | 5 votes |
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); final RelativeLayout frame = (RelativeLayout) findViewById(R.id.frame); final Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.b128); final BubbleView bubbleView = new BubbleView(getApplicationContext(), bitmap); frame.addView(bubbleView); new Thread(new Runnable() { @Override public void run() { while (bubbleView.move()) { bubbleView.postInvalidate(); try { Thread.sleep(1000); } catch (InterruptedException e) { Log.i(TAG, "InterruptedException"); } } } }).start(); }
Example 9
Source File: EditPageLand.java From MyHearts with Apache License 2.0 | 5 votes |
public void onCreate() { super.onCreate(); int screenHeight = R.getScreenHeight(activity); float ratio = ((float) screenHeight) / DESIGN_SCREEN_WIDTH; maxBodyHeight = 0; llPage = new LinearLayout(activity); llPage.setOrientation(LinearLayout.VERTICAL); activity.setContentView(llPage); rlTitle = new RelativeLayout(activity); rlTitle.setBackgroundColor(0xffe6e9ec); int titleHeight = (int) (DESIGN_TITLE_HEIGHT_L * ratio); LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, titleHeight); llPage.addView(rlTitle, lp); initTitle(rlTitle, ratio); RelativeLayout rlBody = new RelativeLayout(activity); rlBody.setBackgroundColor(0xffffffff); lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); llPage.addView(rlBody, lp); initBody(rlBody, ratio); LinearLayout llShadow = new LinearLayout(activity); llShadow.setOrientation(LinearLayout.VERTICAL); rlBody.addView(llShadow, new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); initShadow(llShadow, ratio); llBottom = new LinearLayout(activity); llBottom.setOrientation(LinearLayout.VERTICAL); lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); llPage.addView(llBottom, lp); initBottom(llBottom, ratio); }
Example 10
Source File: EditPageLand.java From Mobike with Apache License 2.0 | 5 votes |
public void onCreate() { super.onCreate(); int screenHeight = R.getScreenHeight(activity); float ratio = ((float) screenHeight) / DESIGN_SCREEN_WIDTH; maxBodyHeight = 0; llPage = new LinearLayout(activity); llPage.setOrientation(LinearLayout.VERTICAL); activity.setContentView(llPage); rlTitle = new RelativeLayout(activity); rlTitle.setBackgroundColor(0xffe6e9ec); int titleHeight = (int) (DESIGN_TITLE_HEIGHT_L * ratio); LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, titleHeight); llPage.addView(rlTitle, lp); initTitle(rlTitle, ratio); RelativeLayout rlBody = new RelativeLayout(activity); rlBody.setBackgroundColor(0xffffffff); lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); llPage.addView(rlBody, lp); initBody(rlBody, ratio); LinearLayout llShadow = new LinearLayout(activity); llShadow.setOrientation(LinearLayout.VERTICAL); rlBody.addView(llShadow, new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); initShadow(llShadow, ratio); llBottom = new LinearLayout(activity); llBottom.setOrientation(LinearLayout.VERTICAL); lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); llPage.addView(llBottom, lp); initBottom(llBottom, ratio); }
Example 11
Source File: BaiduDialog.java From dcs-sdk-java with Apache License 2.0 | 5 votes |
private void setUpWebView() { webViewContainer = new RelativeLayout(getContext()); mWebView = new BaseWebView(getContext().getApplicationContext()); mWebView.setWebViewClient(new BdWebViewClient()); mWebView.setWebChromeClient(new BdWebChromeClient()); mWebView.loadUrl(mUrl); mWebView.setLayoutParams(MATCH); mWebView.setVisibility(View.INVISIBLE); webViewContainer.addView(mWebView); mContent.addView(webViewContainer, MATCH); }
Example 12
Source File: EditPageLand.java From Social with Apache License 2.0 | 5 votes |
public void onCreate() { super.onCreate(); int screenHeight = R.getScreenHeight(activity); float ratio = ((float) screenHeight) / DESIGN_SCREEN_WIDTH; maxBodyHeight = 0; llPage = new LinearLayout(activity); llPage.setOrientation(LinearLayout.VERTICAL); activity.setContentView(llPage); rlTitle = new RelativeLayout(activity); rlTitle.setBackgroundColor(0xffe6e9ec); int titleHeight = (int) (DESIGN_TITLE_HEIGHT_L * ratio); LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, titleHeight); llPage.addView(rlTitle, lp); initTitle(rlTitle, ratio); RelativeLayout rlBody = new RelativeLayout(activity); rlBody.setBackgroundColor(0xffffffff); lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); llPage.addView(rlBody, lp); initBody(rlBody, ratio); LinearLayout llShadow = new LinearLayout(activity); llShadow.setOrientation(LinearLayout.VERTICAL); rlBody.addView(llShadow, new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); initShadow(llShadow, ratio); llBottom = new LinearLayout(activity); llBottom.setOrientation(LinearLayout.VERTICAL); lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); llPage.addView(llBottom, lp); initBottom(llBottom, ratio); }
Example 13
Source File: FlowerFragment.java From Backboard with Apache License 2.0 | 4 votes |
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { mRootView = (RelativeLayout) inflater.inflate(R.layout.fragment_flower, container, false); mCircles = new View[6]; mCircle = mRootView.findViewById(R.id.circle); final float diameter = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, DIAMETER, getResources().getDisplayMetrics()); final TypedArray circles = getResources().obtainTypedArray(R.array.circles); // layout params final RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams((int) diameter, (int) diameter); params.addRule(RelativeLayout.CENTER_IN_PARENT); // create the circle views int colorIndex = 0; for (int i = 0; i < mCircles.length; i++) { mCircles[i] = new View(getActivity()); mCircles[i].setLayoutParams(params); mCircles[i].setBackgroundDrawable(getResources().getDrawable( circles.getResourceId(colorIndex, -1))); colorIndex++; if (colorIndex >= circles.length()) { colorIndex = 0; } mRootView.addView(mCircles[i], 0); } circles.recycle(); /* Animations! */ final SpringSystem springSystem = SpringSystem.create(); // create spring final Spring spring = springSystem.createSpring(); // add listeners along arc final double arc = 2 * Math.PI / mCircles.length; for (int i = 0; i < mCircles.length; i++) { View view = mCircles[i]; // map spring to a line segment from the center to the edge of the ring spring.addListener(new MapPerformer(view, View.TRANSLATION_X, 0, 1, 0, (float) (RING_DIAMETER * Math.cos(i * arc)))); spring.addListener(new MapPerformer(view, View.TRANSLATION_Y, 0, 1, 0, (float) (RING_DIAMETER * Math.sin(i * arc)))); spring.setEndValue(CLOSED); } final ToggleImitator imitator = new ToggleImitator(spring, CLOSED, OPEN); // move circle using finger, snap when near another circle, and bloom when touched new Actor.Builder(SpringSystem.create(), mCircle) .addMotion(new SnapImitator(MotionProperty.X), View.TRANSLATION_X) .addMotion(new SnapImitator(MotionProperty.Y), View.TRANSLATION_Y) .onTouchListener(imitator) .build(); return mRootView; }
Example 14
Source File: EditPagePort.java From POCenter with MIT License | 4 votes |
private void initBody(RelativeLayout rlBody, float ratio) { svContent = new ScrollView(activity); rlBody.addView(svContent, new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); LinearLayout llContent = new LinearLayout(activity); llContent.setOrientation(LinearLayout.VERTICAL); svContent.addView(llContent, new ScrollView.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); etContent = new EditText(activity); int padding = (int) (DESIGN_LEFT_PADDING * ratio); etContent.setPadding(padding, padding, padding, padding); etContent.setBackgroundDrawable(null); etContent.setTextColor(0xff3b3b3b); etContent.setTextSize(TypedValue.COMPLEX_UNIT_SP, 21); etContent.setText(sp.getText()); LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); llContent.addView(etContent, lp); etContent.addTextChangedListener(this); rlThumb = new RelativeLayout(activity); rlThumb.setBackgroundColor(0xff313131); int thumbWidth = (int) (DESIGN_THUMB_HEIGHT * ratio); int xWidth = (int) (DESIGN_REMOVE_THUMB_HEIGHT * ratio); lp = new LinearLayout.LayoutParams(thumbWidth, thumbWidth); lp.leftMargin = lp.rightMargin = lp.bottomMargin = lp.topMargin = padding; llContent.addView(rlThumb, lp); aivThumb = new AsyncImageView(activity) { public void onImageGot(String url, Bitmap bm) { thumb = bm; super.onImageGot(url, bm); } }; aivThumb.setScaleToCropCenter(true); RelativeLayout.LayoutParams rllp = new RelativeLayout.LayoutParams(thumbWidth, thumbWidth); rlThumb.addView(aivThumb, rllp); aivThumb.setOnClickListener(this); initThumb(aivThumb); xvRemove = new XView(activity); xvRemove.setRatio(ratio); rllp = new RelativeLayout.LayoutParams(xWidth, xWidth); rllp.addRule(RelativeLayout.ALIGN_PARENT_TOP); rllp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); rlThumb.addView(xvRemove, rllp); xvRemove.setOnClickListener(this); }
Example 15
Source File: ProgressBarHandler.java From SampleApp with Apache License 2.0 | 4 votes |
public ProgressBarHandler(Context context) { ViewGroup layout = (ViewGroup) ((Activity) context).findViewById(android.R.id.content).getRootView(); mProgressBar = new ProgressBar(context, null); mProgressBar.setIndeterminate(true); mProgressBar.getIndeterminateDrawable().setColorFilter(ContextCompat.getColor(context, R.color.colorPrimary), android.graphics.PorterDuff.Mode.MULTIPLY); RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT); RelativeLayout rl = new RelativeLayout(context); rl.setGravity(Gravity.CENTER); rl.addView(mProgressBar); layout.addView(rl, params); hideProgress(); }
Example 16
Source File: EditPageLand.java From GithubApp with Apache License 2.0 | 4 votes |
private void initBody(RelativeLayout rlBody, float ratio) { svContent = new ScrollView(activity); rlBody.addView(svContent, new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); LinearLayout llContent = new LinearLayout(activity); llContent.setOrientation(LinearLayout.HORIZONTAL); svContent.addView(llContent, new ScrollView.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); etContent = new EditText(activity); int padding = (int) (DESIGN_LEFT_PADDING * ratio); etContent.setPadding(padding, padding, padding, padding); etContent.setBackgroundDrawable(null); etContent.setTextColor(0xff3b3b3b); etContent.setTextSize(TypedValue.COMPLEX_UNIT_SP, 21); etContent.setText(sp.getText()); LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(0, LayoutParams.WRAP_CONTENT); lp.weight = 1; llContent.addView(etContent, lp); etContent.addTextChangedListener(this); rlThumb = new RelativeLayout(activity); rlThumb.setBackgroundColor(0xff313131); int thumbWidth = (int) (DESIGN_THUMB_HEIGHT_L * ratio); int xWidth = (int) (DESIGN_REMOVE_THUMB_HEIGHT_L * ratio); lp = new LinearLayout.LayoutParams(thumbWidth, thumbWidth); lp.rightMargin = lp.bottomMargin = lp.topMargin = padding; llContent.addView(rlThumb, lp); aivThumb = new AsyncImageView(activity) { public void onImageGot(String url, Bitmap bm) { thumb = bm; super.onImageGot(url, bm); } }; aivThumb.setScaleToCropCenter(true); RelativeLayout.LayoutParams rllp = new RelativeLayout.LayoutParams(thumbWidth, thumbWidth); rlThumb.addView(aivThumb, rllp); aivThumb.setOnClickListener(this); initThumb(aivThumb); xvRemove = new XView(activity); xvRemove.setRatio(ratio); rllp = new RelativeLayout.LayoutParams(xWidth, xWidth); rllp.addRule(RelativeLayout.ALIGN_PARENT_TOP); rllp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); rlThumb.addView(xvRemove, rllp); xvRemove.setOnClickListener(this); }
Example 17
Source File: TimerListFragment.java From TwistyTimer with GNU General Public License v3.0 | 4 votes |
private void updateEasterEggs(RelativeLayout root) { DateTime date = new DateTime(DateTime.now()); // April 1st (April Fools) if (date.getMonthOfYear() == 4 && date.getDayOfMonth() == 1) { View clippyView = LayoutInflater.from(mContext).inflate(R.layout.item_easteregg_clippy, null); RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT ); layoutParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE); layoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, RelativeLayout.TRUE); layoutParams.rightMargin = ThemeUtils.dpToPix(mContext, 8); layoutParams.bottomMargin = ThemeUtils.dpToPix(mContext, 8); String[] clippyLines = { "It looks like you're having some trouble on that last layer.\n\nWould you like me to throw your cube away?", "Wow, is that a 10 by 10??", "It looks like you're relying too much on magnets\n\nWould you like to swap your cube for a Rubiks™ brand?", "Hey there, I'm Clippy, your new cubing assistant!", "I have a friend that can solve it in like, 3 seconds", "I mean, it's not that hard. Just some algorithms, right?", "It looks like you're trying to become color neutral.\n\nDid I mention I'm colorblind?", "To be honest, I just peel the stickers off", "I was walking through a cemetery once and saw a ghost cube.\n\nScary stuff.", "It looks like you're abusing that table too much\n\nWould you like to learn a real one-handed method?", "It looks like you're having some trouble with that 4x4 parity\n\nWould you like me to just peel off the stickers?", "I am Clippy. I am ethereal, ETERNAL-Oh, hey!\n\nWould you like some help?", "I once got six N perms in a row.\n\nI still have nightmares about that.", "I once solved like five sides, couldn't quite figure out the last one", "I CAN'T BELIEVE YOU GOT THAT PB, JUST AS MY SD CARD RUNS OUT", "I once used my Pyraminx as a fork. True story.", "Do you stop the timer with your feet too? Yuck.", "In the abscence of a rock, a Megaminx makes a great substitute.\n\nOr so I've heard.", "It is the year 2049. You have been cubing non-stop for over 30 years now.\n\nDon't you think it's time to take a break?" }; TextView clippyText = clippyView.findViewById(R.id.clippy_text); clippyText.setText(clippyLines[new Random().nextInt(clippyLines.length)]); clippyView.setOnClickListener(v -> clippyView.animate() .alpha(0) .setDuration(300) .withEndAction(() -> clippyView.setVisibility(View.GONE))); root.addView(clippyView, layoutParams); } }
Example 18
Source File: XBanner.java From XBanner with Apache License 2.0 | 4 votes |
private void initView() { /*设置指示器背景容器*/ RelativeLayout pointContainerRl = new RelativeLayout(getContext()); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { pointContainerRl.setBackground(mPointContainerBackgroundDrawable); } else { pointContainerRl.setBackgroundDrawable(mPointContainerBackgroundDrawable); } /*设置内边距*/ pointContainerRl.setPadding(mPointContainerLeftRightPadding, mPointTopBottomPading, mPointContainerLeftRightPadding, mPointTopBottomPading); /*设定指示器容器布局及位置*/ mPointContainerLp = new LayoutParams(RMP, RWC); mPointContainerLp.addRule(mPointContainerPosition); if (mIsClipChildrenMode) { mPointContainerLp.setMargins(mClipChildrenLeftRightMargin, 0, mClipChildrenLeftRightMargin, mClipChildrenTopBottomMargin); } addView(pointContainerRl, mPointContainerLp); mPointRealContainerLp = new LayoutParams(RWC, RWC); /*设置指示器容器*/ if (mIsNumberIndicator) { mNumberIndicatorTv = new TextView(getContext()); mNumberIndicatorTv.setId(R.id.xbanner_pointId); mNumberIndicatorTv.setGravity(Gravity.CENTER); mNumberIndicatorTv.setSingleLine(true); mNumberIndicatorTv.setEllipsize(TextUtils.TruncateAt.END); mNumberIndicatorTv.setTextColor(mTipTextColor); mNumberIndicatorTv.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTipTextSize); mNumberIndicatorTv.setVisibility(View.INVISIBLE); if (mNumberIndicatorBackground != null) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { mNumberIndicatorTv.setBackground(mNumberIndicatorBackground); } else { mNumberIndicatorTv.setBackgroundDrawable(mNumberIndicatorBackground); } } pointContainerRl.addView(mNumberIndicatorTv, mPointRealContainerLp); } else { mPointRealContainerLl = new LinearLayout(getContext()); mPointRealContainerLl.setOrientation(LinearLayout.HORIZONTAL); mPointRealContainerLl.setId(R.id.xbanner_pointId); pointContainerRl.addView(mPointRealContainerLl, mPointRealContainerLp); } /*设置指示器是否可见*/ if (mPointRealContainerLl != null) { if (mPointsIsVisible) { mPointRealContainerLl.setVisibility(View.VISIBLE); } else { mPointRealContainerLl.setVisibility(View.GONE); } } /*设置提示语*/ LayoutParams pointLp = new LayoutParams(RMP, RWC); pointLp.addRule(CENTER_VERTICAL); if (mIsShowTips) { mTipTv = new TextView(getContext()); mTipTv.setGravity(Gravity.CENTER_VERTICAL); mTipTv.setSingleLine(true); if (mIsTipsMarquee) { mTipTv.setEllipsize(TextUtils.TruncateAt.MARQUEE); mTipTv.setMarqueeRepeatLimit(3); mTipTv.setSelected(true); } else { mTipTv.setEllipsize(TextUtils.TruncateAt.END); } mTipTv.setTextColor(mTipTextColor); mTipTv.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTipTextSize); pointContainerRl.addView(mTipTv, pointLp); } /*设置指示器布局位置*/ if (CENTER == mPointPosition) { mPointRealContainerLp.addRule(RelativeLayout.CENTER_HORIZONTAL); pointLp.addRule(RelativeLayout.LEFT_OF, R.id.xbanner_pointId); } else if (LEFT == mPointPosition) { mPointRealContainerLp.addRule(RelativeLayout.ALIGN_PARENT_LEFT); if (mTipTv != null) { mTipTv.setGravity(Gravity.CENTER_VERTICAL | Gravity.RIGHT); } pointLp.addRule(RelativeLayout.RIGHT_OF, R.id.xbanner_pointId); } else if (RIGHT == mPointPosition) { mPointRealContainerLp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); pointLp.addRule(RelativeLayout.LEFT_OF, R.id.xbanner_pointId); } setBannerPlaceholderDrawable(); }
Example 19
Source File: FriendListPage.java From YiZhi with Apache License 2.0 | 4 votes |
private void initTitle(RelativeLayout rlTitle, float ratio) { tvCancel = new TextView(activity); tvCancel.setTextColor(0xff3b3b3b); tvCancel.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18); tvCancel.setGravity(Gravity.CENTER); int resId = ResHelper.getStringRes(activity, "ssdk_oks_cancel"); if (resId > 0) { tvCancel.setText(resId); } int padding = (int) (DESIGN_LEFT_PADDING * ratio); tvCancel.setPadding(padding, 0, padding, 0); RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); rlTitle.addView(tvCancel, lp); tvCancel.setOnClickListener(this); TextView tvTitle = new TextView(activity); tvTitle.setTextColor(0xff3b3b3b); tvTitle.setTextSize(TypedValue.COMPLEX_UNIT_SP, 22); tvTitle.setGravity(Gravity.CENTER); resId = ResHelper.getStringRes(activity, "ssdk_oks_contacts"); if (resId > 0) { tvTitle.setText(resId); } lp = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); lp.addRule(RelativeLayout.CENTER_IN_PARENT); rlTitle.addView(tvTitle, lp); tvConfirm = new TextView(activity); tvConfirm.setTextColor(0xffff6d11); tvConfirm.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18); tvConfirm.setGravity(Gravity.CENTER); resId = ResHelper.getStringRes(activity, "ssdk_oks_confirm"); if (resId > 0) { tvConfirm.setText(resId); } tvConfirm.setPadding(padding, 0, padding, 0); lp = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); lp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); rlTitle.addView(tvConfirm, lp); tvConfirm.setOnClickListener(this); }
Example 20
Source File: BaseHeaderActivity.java From CloudReader with Apache License 2.0 | 4 votes |
@Override public void setContentView(@LayoutRes int layoutResID) { View ll = getLayoutInflater().inflate(R.layout.activity_header_base, null); // 内容 bindingContentView = DataBindingUtil.inflate(getLayoutInflater(), layoutResID, null, false); // 头部 bindingHeaderView = DataBindingUtil.inflate(getLayoutInflater(), setHeaderLayout(), null, false); // 标题 bindingTitleView = DataBindingUtil.inflate(getLayoutInflater(), R.layout.base_header_title_bar, null, false); // title (如自定义很强可以拿出去) RelativeLayout.LayoutParams titleParams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); bindingTitleView.getRoot().setLayoutParams(titleParams); RelativeLayout mTitleContainer = (RelativeLayout) ll.findViewById(R.id.title_container); mTitleContainer.addView(bindingTitleView.getRoot()); // header RelativeLayout.LayoutParams headerParams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); bindingHeaderView.getRoot().setLayoutParams(headerParams); RelativeLayout mHeaderContainer = (RelativeLayout) ll.findViewById(R.id.header_container); mHeaderContainer.addView(bindingHeaderView.getRoot()); // content RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); bindingContentView.getRoot().setLayoutParams(params); RelativeLayout mContainer = ll.findViewById(R.id.container); mContainer.addView(bindingContentView.getRoot()); getWindow().setContentView(ll); loadingView = ((ViewStub) getView(R.id.vs_loading)).inflate(); // 设置自定义元素共享切换动画 // setMotion(setHeaderPicView(), false); // 初始化滑动渐变 // initSlideShapeTheme(setHeaderImgUrl(), setHeaderImageView()); // 设置toolbar setToolBar(); ImageView img = loadingView.findViewById(R.id.img_progress); // 加载动画 mAnimationDrawable = (AnimationDrawable) img.getDrawable(); // 默认进入页面就开启动画 if (!mAnimationDrawable.isRunning()) { mAnimationDrawable.start(); } bindingContentView.getRoot().setVisibility(View.GONE); }