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
76
votes
6 answers

android - listview get item view by position

I have listview with custom adapter (base adapter). I want to get view from listview by position. I tried mListView.getChildAt(position) , but it is not working. How can i get item view by position?
alashow
  • 2,735
  • 3
  • 21
  • 47
76
votes
2 answers

What is an Android DecorView?

http://developer.android.com/reference/android/view/Window.html#getDecorView(): Retrieve the top-level window decor view (containing the standard window frame/decorations and the client's content inside of that), which can be added as a …
nmr
  • 16,625
  • 10
  • 53
  • 67
73
votes
11 answers

Android: why setVisibility(View.GONE); or setVisibility(View.INVISIBLE); do not work

I want my DatePicker and the button to be invisible in the begining. And when I press my magic button I want to setVisibility(View.Visible); The problem here is when I setVisibility(View.GONE) or setVisibility(View.INVISIBLE) nothing changes and the…
nayden
  • 875
  • 2
  • 7
  • 10
71
votes
14 answers

Prevent BottomSheetDialogFragment covering navigation bar

I'm using really naive code to show a bottom sheet dialog fragment: class LogoutBottomSheetFragment : BottomSheetDialogFragment() { override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View?…
oferiko
  • 1,927
  • 2
  • 16
  • 17
70
votes
16 answers

setVisibility(GONE) view becomes invisible but still occupies space

I've got a view that is effectively is a button. Here is its XML layout (add_new.xml)
Denys
  • 4,287
  • 8
  • 50
  • 80
68
votes
1 answer

How to make Beautiful & Stylish apps like Timely

A Quote from Google in terms of Designing, and some example of apps: Based on what Google said in http://developer.android.com/ within design section, a developer should consider three goals: Enchant me Simplify my life Make me amazing Which BTW…
66
votes
3 answers

Custom view ... overrides onTouchEvent but not performClick

I get this warning (from the question title) in a custom Android view I am developing. Why do I get warned? What's the logic behind it i.e. why is it a good practice to also override performClick when you override onTouchEvent?
peter.petrov
  • 38,363
  • 16
  • 94
  • 159
65
votes
7 answers

How can you tell if a View is visible on screen in Android?

I want to check if a View within a ScrollView is currently visible in Android. I am not checking if it is focused on yet but if it is currently being displayed on screen. Is there a method in View that can tell me if the view is currently visible?
user1847544
  • 957
  • 2
  • 9
  • 17
63
votes
3 answers

Android - Attempt to invoke virtual method 'void android.view.View.getBoundsOnScreen(android.graphics.Rect)' on a null object reference

I have a simple address form like this: Java: public class NewAddressActivity extends AppCompatActivity { private TextInputLayout mStreetLayout; private TextInputLayout mNumberLayout; private TextInputLayout mNeighborhoodLayout; private…
Douglas Fornaro
  • 2,017
  • 2
  • 22
  • 30
61
votes
3 answers

What does top, left, right and bottom mean in Android Rect object

I have an Android project where I should make Apples fall. The apples are painted in a Rect. So I created a function that change the Rect position and repaint. Here's my function : private void updateApplesPosition() { for(Rect…
Hunsu
  • 3,281
  • 7
  • 29
  • 64
60
votes
4 answers

When it's necessary to execute invalidate() on a View?

My answer to this question was just accepted but I started to wonder when exactly one needs to invalidate() a View and when it is not necessary? After a bit of thinking I came to realization that it should work more or less like this: actual…
mjaskowski
  • 1,479
  • 1
  • 12
  • 16
59
votes
15 answers

Disable the touch events for all the views

What's the best way to disable the touch events for all the views?
Gratzi
  • 4,633
  • 12
  • 42
  • 58
55
votes
7 answers

No resource identifier found for attribute '...' in package 'com.app....'

I've imported a project from Eclipse to Android studio. It utilizes a custom view: xmlns:app="http://schemas.android.com/apk/res-auto" I get errors in the lines below from activity_ro.xml file like: "Error:(136) No resource identifier found for…
kevthanewversi
  • 3,686
  • 4
  • 27
  • 27
53
votes
3 answers

Why isn't there a getContentView() method for Activity?

The Activity class has a setContentView() method. The PopupWindow Class has a getContentView() method but nothing else does. Is there another way to get the main content view for an activity?
kencorbin
  • 1,958
  • 1
  • 20
  • 18
52
votes
4 answers

Disable dark fading in Navigation Drawer

Is there a way to disable the dark fading effect for the background view in the Navigation Drawer View in Android?
Archedius
  • 2,887
  • 3
  • 20
  • 24