Best code examples for Android View class (android.view.View)

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android View class.
You can now enable Codota on your own code to easily search and navigate your Java codebase.

Android View examples from Open Source projects
This code example shows how to use the following methods: setBackgroundColor, setLayoutParams, setVisibility, addView, addContentView
134:	mCustomViewContainer = new FrameLayout(activity); 
135:	mCustomViewContainer.setBackgroundColor(Color.BLACK); 
136:	mCustomViewContainer.setLayoutParams(params); 
137:	activity.getWindow().addContentView(mCustomViewContainer, params); 
-
139:	mCustomViewContainer.addView(view); 
-
142:	mCustomViewContainer.setVisibility(View.VISIBLE); 
Full Snippet Info
9
CodeRank
This code example shows how to use the following methods: setId, setLayoutParams, setOrientation
61:	LinearLayout layout = new LinearLayout(this); 
62:	layout.setOrientation(LinearLayout.VERTICAL); 
63:	layout.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, 
-
65:	layout.setId(FRAGMENT_ID); 
Full Snippet Info
9
CodeRank
This code example shows how to use the following methods: setBackgroundColor, setLayoutParams, addView, setOrientation
78:	root = new LinearLayout(this); 
79:	root.setOrientation(LinearLayout.VERTICAL); 
80:	root.setBackgroundColor(Color.BLACK); 
81:	root.setLayoutParams(containerParams); 
-
111:	root.addView(appView); 
Full Snippet Info
9
CodeRank
This code example shows how to use the following methods: getVisibility, setImageDrawable, setVisibility
218:	mIconView.setImageDrawable(showIcon ? icon : null); 
-
220:	if (mIconView.getVisibility() != VISIBLE) { 
221:	mIconView.setVisibility(VISIBLE); 
-
224:	mIconView.setVisibility(GONE); 
Full Snippet Info
9
CodeRank
This code example shows how to use the following methods: measure, setBackground, layout, draw, dispatchOnPreDraw
76:	FrameLayout content = new FrameLayout(context); 
-
80:	content.setBackground(d); 
-
83:	AttachInfo_Accessor.setAttachInfo(content); 
-
91:	content.measure(w_spec, h_spec); 
-
94:	content.layout(0, 0, w, h); 
-
97:	AttachInfo_Accessor.dispatchOnPreDraw(content); 
-
111:	content.draw(canvas); 
Full Snippet Info
9
CodeRank
This code example shows how to use the following methods: setTag, addView, setOrientation
50:	LinearLayout layout=new LinearLayout(ctxt); 
-
58:	layout.setOrientation(LinearLayout.HORIZONTAL); 
-
78:	layout.addView(rate); 
79:	layout.addView(guts); 
-
81:	wrap=new ViewWrapper(layout); 
-
83:	layout.setTag(wrap); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: getLayoutParams, getWidth, getMax, getProgress, setProgress
143:	mProgressBar.setProgress(mDuration - remaining); 
-
150:	params = (RelativeLayout.LayoutParams) mProgressBar.getLayoutParams(); 
151:	int contentWidth = mProgressBar.getWidth() - (params.leftMargin + params.rightMargin); 
152:	int leadingEdge = ((contentWidth * mProgressBar.getProgress()) / 
153:	mProgressBar.getMax()) + params.leftMargin; 
Full Snippet Info
9
CodeRank
This code example shows how to use the following methods: setFocusable, setFocusableInTouchMode, setLayoutParams, setOnKeyListener, getImeOptions
67:	textView.setOnKeyListener(this); 
-
70:	textView.setLayoutParams(textBoxLayoutParams); 
71:	textView.setFocusable(true); 
72:	textView.setFocusableInTouchMode(true); 
73:	textView.setImeOptions(textView.getImeOptions() | EditorInfo.IME_FLAG_NO_EXTRACT_UI); 
Full Snippet Info
9
CodeRank
This code example shows how to use the following methods: setMinimumHeight, setMinimumWidth
109:	View v = new View(mContext); 
110:	v.setMinimumWidth(0); 
111:	v.setMinimumHeight(0); 
Full Snippet Info
9
CodeRank
This code example shows how to use the following methods: getScrollX, getScrollY, getLayout, getTotalPaddingLeft, getTotalPaddingTop
38:	x -= widget.getTotalPaddingLeft(); 
39:	y -= widget.getTotalPaddingTop(); 
-
41:	x += widget.getScrollX(); 
42:	y += widget.getScrollY(); 
-
44:	Layout layout = widget.getLayout(); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: ofFloat, setAlpha, setVisibility
37:	Animator anim = ObjectAnimator.ofFloat(ecaView, "alpha", 0f); 
-
39:	anim.addListener(new AnimatorListenerAdapter() { 
-
54:	ecaView.setAlpha(0f); 
55:	ecaView.setVisibility(View.INVISIBLE); 
Full Snippet Info
9
CodeRank
This code example shows how to use the following methods: getPaddingBottom, getPaddingLeft, getPaddingRight, setPadding
229:	mRefreshView.setPadding( 
230:	mRefreshView.getPaddingLeft(), 
-
232:	mRefreshView.getPaddingRight(), 
233:	mRefreshView.getPaddingBottom()); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: setId, setLayoutParams, setIndeterminate, setVisibility
67:	mProgressBar = new ProgressBar(context); 
-
70:	mProgressBar.setLayoutParams(progressLayoutParams); 
71:	mProgressBar.setId(INTERNAL_PROGRESS_ID); 
72:	mProgressBar.setIndeterminate(true); 
73:	mProgressBar.setVisibility(View.GONE); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: getContext, getHeight, getLocationOnScreen, getWidth, getWindowVisibleDisplayFrame
83:	view.getLocationOnScreen(screenPos); 
84:	view.getWindowVisibleDisplayFrame(displayFrame); 
-
86:	final Context context = view.getContext(); 
87:	final int viewWidth = view.getWidth(); 
88:	final int viewHeight = view.getHeight(); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: getHeight, getLeft, getParent, getTop, getWidth
237:	if (view == null || view.getParent() == null) { 
-
245:	((View)view.getParent()).invalidate( 
-
254:	final float w = view.getWidth(); 
255:	final float h = view.getHeight(); 
-
265:	r.offset(view.getLeft(), view.getTop()); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: setId, setVisibility, setGravity, setPadding, setText
95:	mStandardEmptyView = new TextView(context); 
96:	mStandardEmptyView.setId(INTERNAL_EMPTY_ID); 
97:	mStandardEmptyView.setGravity(Gravity.CENTER); 
98:	mStandardEmptyView.setVisibility(View.GONE); 
99:	mStandardEmptyView.setPadding(10, 15, 10, 15); 
100:	mStandardEmptyView.setText("That's all, folks!"); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: getMeasuredHeight, getMeasuredWidth, getVisibility, layout
400:	if (enableZoomControls && zoomControls.getVisibility() == View.VISIBLE) { 
401:	int zoomWidth = zoomControls.getMeasuredWidth(); 
402:	int zoomHeight = zoomControls.getMeasuredHeight(); 
403:	zoomControls.layout(parentRight - zoomWidth, parentBottom - zoomHeight, parentRight, parentBottom); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: getHeight, getLeft, getWidth, layout
81:	v.layout(v.getLeft() + dx, 0, v.getLeft() + dx + v.getWidth(), v.getHeight()); 
82:	ViewUtils.printView("menu", v); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: requestLayout, addView, removeAllViews
150:	view.removeAllViews(); 
-
153:	view.addView(progress); 
154:	view.addView(label); 
155:	view.requestLayout(); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: findViewById, isFocused, requestFocus, setOnFocusChangeListener
89:	final View viewToBeFocused = mView.findViewById(editViewId); 
-
95:	if (viewToBeFocused.isFocused()) { 
-
102:	viewToBeFocused.setOnFocusChangeListener(this); 
103:	final boolean requestFocusResult = viewToBeFocused.requestFocus(); 
-
107:	viewToBeFocused.setOnFocusChangeListener(null); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: getHolder, setLayoutParams
61:	mSurfaceView = new SurfaceView(this); 
62:	mSurfaceView.setLayoutParams(surfaceParams); 
-
77:	mSurfaceHolder = mSurfaceView.getHolder(); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: getHeight, getLocationOnScreen, getWidth
227:	anchor.getLocationOnScreen(loc); 
228:	mRect.set(loc[0], loc[1], loc[0] + anchor.getWidth(), loc[1] + anchor.getHeight()); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: getBottom, getLeft, getRight, getTop
106:	mStackedBackground.setBounds(mTabContainer.getLeft(), mTabContainer.getTop(), 
107:	mTabContainer.getRight(), mTabContainer.getBottom()); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: getHeight, getLeft, getParent, getTop, getWidth
158:	final float w = view.getWidth(); 
159:	final float h = view.getHeight(); 
-
169:	r.offset(view.getLeft(), view.getTop()); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: getContext, loadDataWithBaseURL, setBackgroundColor, setWebViewClient
146:	String source = getSource(wv.getContext()); 
-
149:	wv.setWebViewClient(this); 
-
152:	wv.loadDataWithBaseURL(null, html, "text/html", "utf-8", null); 
153:	wv.setBackgroundColor(color); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: getParent, removeView
92:	ViewParent newEmptyViewParent = newEmptyView.getParent(); 
-
95:	((ViewGroup) newEmptyViewParent).removeView(newEmptyView); 
-
105:	.setEmptyViewInternal(newEmptyView); 
-
107:	this.mRefreshableView.setEmptyView(newEmptyView); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: setLayoutParams, setGravity, setText
122:	TextView tv = new TextView(getActivity()); 
123:	tv.setLayoutParams(new ViewGroup.LayoutParams(MATCH_PARENT, 
-
125:	tv.setText("Fragment #" + mNum); 
126:	tv.setGravity(CENTER); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: getVisibility, setImageDrawable, setVisibility
212:	mIconView.setImageDrawable(showIcon ? icon : null); 
-
214:	if (mIconView.getVisibility() != VISIBLE) { 
215:	mIconView.setVisibility(VISIBLE); 
-
218:	mIconView.setVisibility(GONE); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: setBackgroundDrawable, addView, addView
147:	containerView = new LinearLayout(context); 
148:	containerView.addView(contentView); 
149:	containerView.setBackgroundDrawable(background); 
150:	getWindowManager().addView(containerView, null); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: setLayoutParams, setCompoundDrawablesWithIntrinsicBounds, setGravity, setPadding, setText
142:	TextView textView = new TextView(ActivityPickerActivity.this); 
143:	textView.setLayoutParams(lpGroup); 
144:	textView.setGravity(Gravity.CENTER_VERTICAL | Gravity.LEFT); 
145:	textView.setPadding(leftPadding, 0, 0, 0); 
-
172:	textView.setText(info.applicationInfo.loadLabel(mPackageManager)); 
173:	textView.setCompoundDrawablesWithIntrinsicBounds(Utilities.createIconThumbnail(info.applicationInfo.loadIcon(mPackageManager),ActivityPickerActivity.this), null, null, null); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: getParent, removeView
91:	ViewParent newEmptyViewParent = newEmptyView.getParent(); 
-
94:	((ViewGroup) newEmptyViewParent).removeView(newEmptyView); 
-
104:	.setEmptyViewInternal(newEmptyView); 
-
106:	this.mRefreshableView.setEmptyView(newEmptyView); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: setLayoutParams, setGravity, setText
136:	TextView tv = new TextView(getActivity()); 
137:	tv.setLayoutParams(new ViewGroup.LayoutParams(MATCH_PARENT, MATCH_PARENT)); 
138:	tv.setText("Fragment #" + mNum); 
139:	tv.setGravity(CENTER); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: getVisibility, setImageDrawable, setVisibility
218:	mIconView.setImageDrawable(showIcon ? icon : null); 
-
220:	if (mIconView.getVisibility() != VISIBLE) { 
221:	mIconView.setVisibility(VISIBLE); 
-
224:	mIconView.setVisibility(GONE); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: getHeight, getLayoutParams
115:	final ViewGroup.LayoutParams params = imageView.getLayoutParams(); 
-
118:	height = imageView.getHeight(); // Get actual image height 
-
121:	if (height <= 0) height = getImageViewFieldValue(imageView, "mMaxHeight"); // Check maxHeight parameter 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: setLayoutParams, setPadding, setImageBitmap, setScaleType
92:	imageView = new ImageView(mContext); 
93:	imageView.setLayoutParams(new GridView.LayoutParams(50, 50)); 
94:	imageView.setScaleType(ImageView.ScaleType.FIT_XY); 
95:	imageView.setPadding(4, 4, 4, 4); 
-
101:	imageView.setImageBitmap(emotions.get(index.get(position))); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: setVisibility, setEllipsize, setSingleLine, setText, setTextAppearance
239:	mTimeTextView = new TextView(mContext); 
240:	mTimeTextView.setSingleLine(true); 
241:	mTimeTextView.setEllipsize(TruncateAt.END); 
242:	mTimeTextView.setTextAppearance(mContext, android.R.style.TextAppearance_Small); 
-
245:	mTimeTextView.setText(text); 
246:	mTimeTextView.setVisibility(View.VISIBLE); 
Full Snippet Info
8
CodeRank
Related Android View Questions & Answers:
Other Android View Examples
21:	  File audiofile = null;
22:	  private static final String TAG = "SoundRecordingActivity";
23:	  private View startButton;
24:	  private View stopButton;
25:	
-
22:	  private static final String TAG = "SoundRecordingActivity";
23:	  private View startButton;
24:	  private View stopButton;
25:	
26:	  @Override
-
32:	  }
33:	
34:	  public void startRecording(View view) throws IOException {
35:	
36:	    startButton.setEnabled(false);
-
53:	  }
54:	
55:	  public void stopRecording(View view) {
56:	    startButton.setEnabled(true);
57:	    stopButton.setEnabled(false);

Read More

15:	    setContentView(R.layout.main);
16:	    // define the contextual action mode
17:	    View view = findViewById(R.id.myView);
18:	    view.setOnLongClickListener(new View.OnLongClickListener() {
19:	      // called when the user long-clicks on someView
-
18:	    view.setOnLongClickListener(new View.OnLongClickListener() {
19:	      // called when the user long-clicks on someView
20:	      public boolean onLongClick(View view) {
21:	        if (mActionMode != null) {
22:	          return false;

Read More

23:	  }
24:	
25:	  public void onClicked(View view) {
26:	    String text = view.getId() == R.id.view1 ? "Background" : "Foreground";
27:	    Toast.makeText(this, text, Toast.LENGTH_SHORT).show();

Read More

5:				@Override
6:				public void onClick(View arg0) {
7:					if(isShuffle){
8:						isShuffle = false;
9:						Toast.makeText(getApplicationContext(), "Shuffle is OFF", Toast.LENGTH_SHORT).show();

Read More

5:				@Override
6:				public void onClick(View arg0) {
7:					if(isRepeat){
8:						isRepeat = false;
9:						Toast.makeText(getApplicationContext(), "Repeat is OFF", Toast.LENGTH_SHORT).show();

Read More

10:	
11:		@Override
12:		public View onCreateView(LayoutInflater inflater, ViewGroup container,
13:				Bundle savedInstanceState) {
14:	
-
13:				Bundle savedInstanceState) {
14:	
15:			View rootView = inflater.inflate(R.layout.fragment_movies, container, false);
16:			
17:			return rootView;

Read More

1:	@MediumTest
2:	public void testInfoTextView_layout() {
3:	    final View decorView = mClickFunActivity.getWindow().getDecorView();
4:	    ViewAsserts.assertOnScreen(decorView, mInfoTextView);
5:	    assertTrue(View.GONE == mInfoTextView.getVisibility());

Read More

1:	someView.setOnLongClickListener(new View.OnLongClickListener() {
2:	    // Called when the user long-clicks on someView
3:	    public boolean onLongClick(View view) {
4:	        if (mActionMode != null) {
5:	            return false;

Read More

1:	@MediumTest
2:	public void testClickMeButton_layout() {
3:	    final View decorView = mClickFunActivity.getWindow().getDecorView();
4:	
5:	    ViewAsserts.assertOnScreen(decorView, mClickMeButton);

Read More

See Code Examples for Android View Methods: