Questions tagged [android-view]

Questions regarding Views in Android. Views may be defined in Android Layout XML or in Java code. Questions using this tag involve general View practices or advice. With regard to specific Views, refer to the info for this tag. For questions regarding layout, use the [android-layout] tag.

Introduction

A View in Android is the display of the data utilized by the application. Views range widely from simple and non-interactive to complex and interactive in many ways. In addition to the Views provided by the SDK, developers have the option to create custom Views. This means that virtually any communication or display to the user may be handled in innumerable ways.

ViewGroups

ViewGroup is a subclass of View, which has the ability to hold other Views. Children Views may be added to the ViewGroup at run-time (in Java code) or may be pre-defined in Android XML. Like Views, ViewGroups may also be extended in the same way. Follow these guidelines for questions regarding ViewGroups:

  • If the ViewGroup is provided by the Android SDK, it should be listed below in Standard Views.
  • If the ViewGroup is a Custom View, use

Standard Views

A wide variety of Views are delivered with the Android SDK for use by developers. These views make up a majority of the Views in a standard application. Each View has its own semantics and behaviors. As a result, it is often more beneficial to use the tags specifically related to those Views. Below is a list of standard views provide within the Android SDK:

Usage: vs.

While Views and layouts work hand-in-hand, questions regarding the two are often very different. These guidelines will help to properly determine which tag to use:

  • If the question refers to the properties used to display the View properly, then use .
  • If, instead, the question refers to the functionality of the View, then is appropriate.
3981 questions
587
votes
15 answers

How to view method information in Android Studio

In Eclipse, when you hover your mouse over a method, a window would appear with a description of what the method does, what the parameters mean and what it returns. Is there a way to get Android Studio to do the same thing?
tyczj
  • 71,600
  • 54
  • 194
  • 296
499
votes
8 answers

Android basics: running code in the UI thread

In the viewpoint of running code in the UI thread, is there any difference between: MainActivity.this.runOnUiThread(new Runnable() { public void run() { Log.d("UI thread", "I am the UI thread"); …
Luky
  • 5,346
  • 4
  • 17
  • 15
457
votes
7 answers

What is the main purpose of setTag() getTag() methods of View?

What is the main purpose of such methods as setTag() and getTag() of View type objects? Am I right in thinking that I can associate any number of objects with a single View?
Eugene
  • 59,186
  • 91
  • 226
  • 333
437
votes
25 answers

Is there an easy way to add a border to the top and bottom of an Android View?

I have a TextView and I'd like to add a black border along its top and bottom borders. I tried adding android:drawableTop and android:drawableBottom to the TextView, but that only caused the entire view to become black.
emmby
  • 99,783
  • 65
  • 191
  • 249
397
votes
14 answers

Android: View.setID(int id) programmatically - how to avoid ID conflicts?

I'm adding TextViews programmatically in a for-loop and add them to an ArrayList. How do I use TextView.setId(int id)? What Integer ID do I come up with so it doesn't conflict with other IDs?
znq
  • 44,613
  • 41
  • 116
  • 144
329
votes
21 answers

Is there an addHeaderView equivalent for RecyclerView?

I'm looking for an equivalent to addHeaderView for a recycler view. Basically I want to have an image with 2 buttons be added as a header to the listview. Is there a different way to add a header view to a recycler view? An example for guidance…
ViciDroid
  • 3,555
  • 4
  • 14
  • 16
288
votes
34 answers

findViewByID returns null

First of all: yes, I read all the other threads on this topic. And not only those from this site... (you see, I'm a little frustrated) Most of them come with the advice to use android:id instead of just id in the XML file. I did. From others, I…
Thomas
  • 2,911
  • 2
  • 16
  • 6
273
votes
12 answers

What does the LayoutInflater attachToRoot parameter mean?

The LayoutInflater.inflate documentation isn't exactly clear to me about the purpose of the attachToRoot parameter. attachToRoot: whether the inflated hierarchy should be attached to the root parameter? If false, root is only used to create the…
Jeff Axelrod
  • 27,676
  • 31
  • 147
  • 246
261
votes
28 answers

Coloring Buttons in Android with Material Design and AppCompat

Before the AppCompat update came out today I was able to change the color of buttons in Android L but not on older versions. After including the new AppCompat update I am unable to change the color for either version, when I do try the button just…
mail929
  • 2,768
  • 3
  • 15
  • 12
238
votes
9 answers

How to lay out Views in RelativeLayout programmatically?

I'm trying to achieve the following programmatically (rather than declaratively via XML):
Dan
  • 2,389
  • 2
  • 14
  • 4
224
votes
6 answers

Usage of forceLayout(), requestLayout() and invalidate()

I'm a bit confused about the roles of forceLayout(), requestLayout() and invalidate() methods of the View class. When shall they be called?
sdabet
  • 18,360
  • 11
  • 89
  • 158
223
votes
5 answers

Same-named attributes in attrs.xml for custom view

I'm writing a few custom views which share some same-named attributes. In their respective section in attrs.xml I'd like to use the same names for attributes:
214
votes
10 answers

ConstraintLayout: change constraints programmatically

I need help with ConstraintSet. My goal is to change view's constraints in code, but I cant figure out how to do this right. I have 4 TextViews and one ImageView. I need to set ImageView constraints to one of the TextViews. check_answer4 =…
Big Coach
  • 2,485
  • 2
  • 12
  • 31
212
votes
3 answers

How can I assign an ID to a view programmatically?

In an XML file, we can assign an ID to a view like android:id="@+id/something" and then call findViewById(), but when creating a view programmatically, how do I assign an ID? I think setId() is not the same as default assignment. setId() is…
212
votes
9 answers

How to get hosting Activity from a view?

I have an Activity with 3 EditTexts and a custom view which acts a specialised keyboard to add information into the EditTexts. Currently I'm passing the Activity into the view so that I can get the currently focused edit text and update the…
mAndroid
  • 5,087
  • 6
  • 25
  • 33
1
2 3
99 100