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
52
votes
2 answers

Are "GONE" views detrimental to performance?

I'm making an app in which it might save me some time to have a single layout for several activities, with some of the views set to GONE depending on which activity is being used. I know that having a large number of views in a layout can lead to…
public static void
  • 1,153
  • 11
  • 20
50
votes
1 answer

Android View setPadding() vs setPaddingRelative()

Based on the Android document which doesn't give much explanation, what's the difference between setPadding() vs setPaddingRelative()?
jerrytouille
  • 1,238
  • 1
  • 13
  • 28
49
votes
4 answers

How to make SearchView always expanded in android?

I have SearchView in the top of the layout (not in the action bar), is there anyway to force this View to be always expanded (opened)? If not, i wish to place fancy image near it, is there anyway to make SearchView hide this image when expanded…
ruruma
  • 603
  • 1
  • 5
  • 8
48
votes
9 answers

Changing CardView shadow color

This question was asked on SO many times, but still I didn't find a good solution for this problem. Why do I need this to do? Well because project me and my team develops has iOS style. What did I try? 9.pathch shadow generator but 9.pathes are…
48
votes
4 answers

Using clipRect - explanation

public class POCII extends Activity { myView mv = new myView(this); @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(mv); } } class myView…
Namratha
  • 16,630
  • 27
  • 90
  • 125
47
votes
3 answers

Shaped drawable with selectableItemBackground as background

I have couple buttons that I need an oval shaped border. So i have this in a capsule_border.xml
46
votes
11 answers

EditText not scrollable inside ScrollView

I have a ScrollView inside which is an EditText which is set to scroll vertically. But it does not scrolls. Instead the whole layout scrolls, Whenever i try to scroll the EditText. Below is the code -
44
votes
5 answers

ConstraintLayout views in top left corner

Every time I create views like Button and TextView in ConstraintLayout, they all get stuck at the top corner instead of where I placed them. I tried to create new activities and change the emulator, but the result is still the same. This is a…
44
votes
8 answers

Is there a way to get current activity's layout and views via adb?

For environment reasons I can only use adb commands. Is there a way to get the current layout attributes like id, position, text etc ? Similar to what uiautomatorviewer shows.
Filipe Arruda
  • 628
  • 1
  • 5
  • 13
44
votes
2 answers

android libvlc multiple surface problems

I would like to know if is possible to use two Surface views in the same layout and view the content of both of them at the same time. In future, I would make use of a Grid-view of video-view, where each video-view uses VLC. I modified this sample…
tulkas85
  • 1,103
  • 1
  • 17
  • 43
43
votes
3 answers

What are WindowInsets?

I am trying to learn about the Android OS and while I was reading the Google I/O 2014 app, I came across the WindowInsets. If anyone can explain what they are then it would be a great help. Thank you.
Samvid Mistry
  • 783
  • 1
  • 8
  • 14
42
votes
5 answers

How can you adjust Android SnackBar to a specific position on screen

Follwing the new android snackbar, i'm trying to set it to be positioned on a specific y coordinate. Its seems to be not even a possible. I've tried with getting the parent of the snackbar's view, but, there's nothing to be done to the parent for it…
Dus
  • 4,052
  • 5
  • 30
  • 49
41
votes
7 answers

how to set width which is equal to another widget on android

I need to draw a horizontal line below a text field such that the width of the line equals the text width (not the width of the full screen). In my app I have a textview below a view(Horizontal line). The width of the line view should be equal to…
M.A.Murali
  • 9,988
  • 36
  • 105
  • 182
40
votes
3 answers

Controlling view visibility from a resources

I have a layout that contains two ImageViews. I want one of them to be visible in portrait and the other in landscape. How do I achieve it using resources? (I know how to set it programmatically for but this specific use I need to achieve it using…
user1139880
  • 1,828
  • 3
  • 18
  • 27
40
votes
6 answers

Get fragment's container view id

I have a fragment added using transaction.add(R.id.content, fragment, null); and I need to start new fragment from this one. But to do this I need to know first fragment's container view id (R.id.content in my case). How can I get this? I can just…
Dmitry Ryadnenko
  • 22,222
  • 4
  • 42
  • 56