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
31
votes
1 answer

When are views attached and detached?

This question is not about how to detect if a view is attached or detached. In general, when is a view attached or detached? Is there a lifecycle diagram for this? To clarify, I'm looking for answers to what happens when: Activity sent to…
William
  • 2,917
  • 5
  • 30
  • 47
30
votes
2 answers

Where does Android View.scrollTo(x, y) scroll to?

scrollTo(int x, int y) says: x the x position to scroll to y the y position to scroll to onScrollChanged(int l, int t, int oldl, int oldt) says: l Current horizontal scroll origin. t Current vertical scroll origin. What I would like to know and…
slybloty
  • 6,346
  • 6
  • 49
  • 70
30
votes
13 answers

How to properly remove padding (or margin?) around buttons in Android?

Currently, I have the following bottom log in button. When button is not being pressed When button is being pressed The XML looks like this
Cheok Yan Cheng
  • 47,586
  • 132
  • 466
  • 875
30
votes
10 answers

DialogFragment not resizing when keyboard shown

I'm trying to use a SherlockDialogFragment to ask some input from the user. Everything works fine on my phone (Galaxy Nexus, 4.2), but on a smaller phone (emulator 2.3.3), when the keyboard shows up, it covers the two buttons of the DialogFragment,…
29
votes
3 answers

How can I add a menu dynamically to bottom navigation view?

Android has new ui element - BottomNavigationView I don't want to contain my menus in the xml files. I will receive the information about menu items and order from backend side. I want to create them dynamically and set into the…
Kiryl Bielašeŭski
  • 2,663
  • 2
  • 28
  • 40
29
votes
6 answers

Dynamically change SVG image color in android

I know that using third party library, it is possible to use SVG image in Android. Library like: svg-android The code to load SVG image is like below: public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //…
Shreyash Mahajan
  • 23,386
  • 35
  • 116
  • 188
28
votes
6 answers

Change Toolbar overflow icon color

I have an android.support.v7.widget Toolbar in my Android app. The background color of this is bright orange and the best looking color on top of this would be white instead of black. I have the default color on black and not white. Since it would…
28
votes
3 answers

Use custom View in a RecyclerView Adapter?

I have a basic custom View which looks like this: public class CustomView extends RelativeLayout { private User user; private ImageView profilePicture; public CustomView(Context context) { super(context); init(); …
28
votes
6 answers

android:fitsSystemWindows not working

In my theme I defined the following rules to draw my views behind the status bar: @android:color/transparent true And in the Activity…
Taig
  • 6,718
  • 4
  • 44
  • 65
28
votes
6 answers

Android : Draw Circle With Text Inside

I need to draw three circles in my fragment ,the circles differ in size, I refer this link The result i obtained is this This is my XML Code : UPDATED
edwin
  • 7,985
  • 10
  • 51
  • 82
28
votes
7 answers

getWidth() and getHeight() always returning 0. Custom view

In a Fragment, I am inflating a Layout with multiple child View. I need to get the dimensions (width and height) of one of them which is a custom view. Inside the custom view class I can do it easily. But if I try to do it from the fragment I…
quinestor
  • 1,432
  • 4
  • 19
  • 40
28
votes
9 answers

Why EditText in a custom compound view is re-using the text entered in another compound view instance?

I'm trying to write a custom compound view composed by a TextView and an EditText, _compound_view.xml_:
moondroid
  • 1,730
  • 17
  • 20
28
votes
7 answers

Android view pager with page indicator

I need to get page indicator in the view pager file with images. Here is my code. public class IndicatorActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle…
28
votes
4 answers

Android equivalent work-around for View.getX() before API 11?

I'm using the getX() and getY() method on a view for some special dragging logic (not animation, i.e. I never use setX/Y methods, I just need the getters to check). However, I've come to realize that these are only available post-API 11. The docs…
cemulate
  • 2,305
  • 1
  • 34
  • 48
27
votes
5 answers

What is the use of "attach to root" in layout inflater?

I am a newbie to android, I know this question has already been asked but i couldn't get a satisfactory explanation. My doubts are: What is "attach to root" used for, if possible with a small and clear example. When I searched for the answer people…
srujan maddula
  • 1,190
  • 2
  • 11
  • 19