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
40
votes
5 answers

How to setContentView in a fragment?

Now I've got this fragment which i want to use setContentView with but so far i cant find how. You can see my case in the code below, im not trying to inflate a layout, im trying to use it with the view called SampleView. So how can I do…
lamp ard
  • 871
  • 2
  • 10
  • 19
39
votes
18 answers

How to disable BottomSheetDialogFragment dragging

How to disable BottomSheetDialogFragment dragging by finger? I saw similar questions, but they're all about BottomSheet not BottomSheetDialogFragment.
39
votes
6 answers

How to use Percentage for android layout?

How can we use percentage values for android view elements? something like this
masoud p
  • 503
  • 1
  • 7
  • 15
38
votes
3 answers

Difference between an AppCompat view and a normal Android view

What is the difference between an AppCompat view component and a standard/default view component? For example, the difference between an AppCompatEditText, and an EditText, or between an AppCompatButton and a Button. Looking at the developer docs…
37
votes
1 answer

Duplicate a view programmatically from an already existing view

I was trying the following code and was getting an error because there is no such constructor defined. View v = new View(findViewById(R.id.divider)); Is there any simple way to copy a view into another?
Mani Sankar
  • 800
  • 1
  • 9
  • 19
36
votes
3 answers

java.lang.IllegalArgumentException: pointerIndex out of range Exception - dispatchTouchEvent

I have this method in my custom view which extends FrameLayout: @Override public boolean dispatchTouchEvent(MotionEvent ev) { int currentItem = vp.getCurrentItem(); if (inDragPanelZone(currentItem, ev.getX(), ev.getY()) && ev.getAction() ==…
Daniel L.
  • 5,060
  • 10
  • 36
  • 59
35
votes
7 answers

ViewTreeLifecycleOwner not found from DecorView@2da7146[MyActivity]

After updating from compose alpha-11 to alpha-12(or beta-01) I am getting this crash whenever I open an activity or fragment that has compose views. I am using AppCompatActivity which implements LifecycleOwner, so this is extremely odd. …
35
votes
4 answers

Difference between setAlpha and setImageAlpha

ImageView has two methods related methods: setAlpha and setImageAlpha. The former is available since API level 1, but is deprecated since level 16. The latter is available since level 16. There's also another setAlpha method, from the View class and…
kolistivra
  • 4,229
  • 9
  • 45
  • 58
35
votes
6 answers

Creating RadioGroup programmatically

I'm getting an Error while working with the following code Error: The specified child already has a parent you must call removeView on the child's parent first Anyone please help me in resolving this Error: RadioButton[] radiobutton = new…
35
votes
2 answers

Android ViewGroup: what should I do in the onLayout() override?

When extending an Android ViewGroup class, what is the purpose of the onLayout() override? I'm making a custom control in Android but for some reason the content (child View objects) isn't displaying. My approach was to extend the ViewGroup class,…
JLindsey
  • 700
  • 2
  • 7
  • 14
34
votes
4 answers

findViewById() not working in a not MainActivity class

I have a text view in my Lyout and I would like to set some text to this textview. This should be made in a class which is not a MainActivity class. The problem is that I got a null pointer exception. Here is my code: public class UserInformations…
Milos Cuculovic
  • 19,631
  • 51
  • 159
  • 265
34
votes
11 answers

Android onClick method doesn't work on a custom view

I've started working on an app. I build the menu yesterday but the onClick method doesn't work! I created a class that extends View and called her MainMenuObject - that class is for any object in the main menu (buttons, logos etc). I've created a…
Elad92
  • 2,471
  • 4
  • 22
  • 36
33
votes
2 answers

Android windowSoftInputMode="adjustPan" scroll some more

Consider the following example for a view:
Airfreshener
  • 826
  • 1
  • 8
  • 18
32
votes
3 answers

Using Android AutoCompleteTextView with ArrayAdapter instead of ArrayAdapter

I wanted to use AutoCompleteTextView in my android application.I know how to use it with simple array of Strings, but I wanted AutoCompleteTextView to use list of Objects to perform completion.My code for this is following: ACTIVITY CODE public…
Anshul
  • 7,914
  • 12
  • 42
  • 65
31
votes
5 answers

java.lang.IllegalStateException: Unable to create layer for v

I have this exception on crashlytics and have no idea how to reproduce or what the cause might be. Does anyone have any pointers as to where I should start looking? Only affects Android 5+. Fatal Exception: java.lang.IllegalStateException: Unable to…
casolorz
  • 8,486
  • 19
  • 93
  • 200