Questions tagged [android-layout]

A layout defines the visual structure for a user interface, such as the UI for an activity, fragment or app widget.

An Android layout defines everything the user can see and touch. A layout is made up of View (like buttons and text) and ViewGroup (like lists, tables, or more Views) objects, all combined to make a View Hierarchy:
View Hierarchy
(from Android's UI Overview)

Designing a Layout:

You can create your layout in any combination of these two ways:

  1. Declare UI elements in XML.
    Android provides a straightforward XML vocabulary that corresponds to the View classes and subclasses, such as those for widgets and layouts.

  2. Instantiate layout elements at runtime.
    Your application can create View and ViewGroup objects (and manipulate their properties) programmatically.

Common Layouts:

Each subclass of the ViewGroup class provides a unique way to display the views you nest within it. Below are some of the more common layout types that are built into the Android platform.

  1. Linear Layout: A layout that organizes its children into a single horizontal or vertical row. It creates a scrollbar if the length of the window exceeds the length of the screen.
  2. Relative Layout: Enables you to specify the location of child objects relative to each other (child A to the left of child B) or to the parent (aligned to the top of the parent).
  3. Constraint Layout: Allows positioning children relative to each other and the parent. But also offers other powerful positioning and sizing strategies, including horizontal/vertical child "chains" with custom spacing/weighting, arbitrary horizontal/vertical "guidelines," and custom child size aspect ratios.
  4. Web View: Displays web pages.
  5. Frame layout: FrameLayout is designed to block out an area on the screen to display a single item.
  6. Grid View: GridView is a ViewGroup that displays items in a two-dimensional, scrollable grid.

Useful Links:

59114 questions
328
votes
10 answers

how to change color of textview hyperlink?

I am using this code for hyperlink: By default it is…
super
  • 4,139
  • 4
  • 23
  • 20
326
votes
25 answers

Changing EditText bottom line color with appcompat v7

I am using appcompat v7 to get the look consistent on Android 5 and less. It works rather well. However I cannot figure out how to change the bottom line color and the accent color for EditTexts. Is it possible? I have tried to define a custom…
Laurent
  • 14,122
  • 13
  • 57
  • 89
311
votes
26 answers

How to change the color of a CheckBox in Android

How do I change the default CheckBox color in Android? By default the CheckBox color is green, and I want to change this color. If it is not possible please tell me how to make a custom CheckBox?
Piyush
  • 5,607
  • 4
  • 27
  • 27
306
votes
15 answers

Add padding on view programmatically

I am developing Android v2.2 app. I have a Fragment. In the onCreateView(...) callback of my fragment class, I inflate an layout to the fragment like below: @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle…
Leem.fin
  • 40,781
  • 83
  • 202
  • 354
303
votes
11 answers

How to animate RecyclerView items when they appear

How can I animate the RecyclerView Items when there are appearing? The default item animator only animates when a data is added or removed after the recycler data has been set. How can this be achieved?
PaulNunezM
  • 3,217
  • 3
  • 14
  • 10
301
votes
13 answers

How to set layout_weight attribute dynamically from code?

How can I set the value for the attribute layout_weight for button in android dynamically from java code ?
Adham
  • 63,550
  • 98
  • 229
  • 344
294
votes
9 answers

How to center the elements in ConstraintLayout

I am using ConstraintLayout in my application to make applications layout. I am trying to a create a screen wheren one EditText and Button should be in center and Button should be below of EditText with a marginTop only 16dp. Here is my layout and…
N Sharma
  • 33,489
  • 95
  • 256
  • 444
293
votes
10 answers

Android LinearLayout Gradient Background

I am having trouble applying a gradient background to a LinearLayout. This should be relatively simple from what I have read but it just doesn't seem to work. For reference sakes I am developing on 2.1-update1. header_bg.xml:
Genesis
  • 8,038
  • 3
  • 21
  • 22
293
votes
34 answers

Android list view inside a scroll view

I have an android layout which has a scrollView with a number of elements with in it. At the bottom of the scrollView I have a listView which is then populated by an adapter. The problem that I am experiencing, is that android is excluding the…
Zapnologica
  • 22,170
  • 44
  • 158
  • 253
285
votes
16 answers

Android: set view style programmatically

Here's XML:
Jim
  • 8,874
  • 16
  • 68
  • 125
280
votes
10 answers

Differences between ConstraintLayout and RelativeLayout

What is the difference between ConstraintLayout and RelativeLayout?
276
votes
26 answers

Android: How to create a Dialog without a title?

I'm trying to generate a custom dialog in Android. I create my Dialog like this: dialog = new Dialog(this); dialog.setContentView(R.layout.my_dialog); Everythings works fine except for the title of the Dialog. Even if I don't set the title of the…
Janusz
  • 187,060
  • 113
  • 301
  • 369
275
votes
7 answers

Avoid passing null as the view root (need to resolve layout parameters on the inflated layout's root element)

Passing null for root studio gives me this warning: Avoid passing null as the view root (need to resolve layout parameters on the inflated layout's root element) It is showing a null value in getGroupView. Please help. public class…
hash
  • 5,336
  • 7
  • 36
  • 59
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
264
votes
13 answers

Placing/Overlapping(z-index) a view above another view in android

I have a linear layout which consists of imageview and textview , one below another in a linear layout.
sat
  • 40,138
  • 28
  • 93
  • 102