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
18
votes
3 answers

set Toolbar height programmatically Android

I am trying to set the height of toolbar programmatically by this way: toolbar.setLayoutParams(new Toolbar.LayoutParams(LayoutParams.MATCH_PARENT, 42)); toolbar.setMinimumHeight(42); But it causes fatal exception with this log ->…
18
votes
3 answers

Using navigationView with tabLayout

So I've recently been working on updating my app to use the new material design support library. My application has one main activity with a drawerLayout and navigation view. The main content of app is shown in a frameLayout, through fragments.…
mlz7
  • 2,067
  • 3
  • 27
  • 51
18
votes
3 answers

How to create something similar to Play Newsstand layout

I am trying to “recreate” (something similar to) the Play Newsstand layout. Per the documentation the general structure for CoordinatorLayout is
Katedral Pillon
  • 14,534
  • 25
  • 99
  • 199
18
votes
2 answers

MultiSelect gesture like Google Photos app

I want to implement multi select gesture in my app like in new Google Photos App here: I have tried following this answer, but couldn't do this. Can anyone just guide me?
18
votes
1 answer

Android SnackBar: error inflating SnackbarLayout

I wanted to try out the new Snackbar from the official design library provided by Google. Its usage is very close to a Toast so I thought it would be simple enough to try out. I've tried it out on an emulator running 5.1 as well as Samsung Galaxy S6…
Andreas N
  • 193
  • 1
  • 1
  • 6
18
votes
6 answers

Set progress bar on top of RecyclerView and remove after data is loaded

I want to have a loading icon that is displayed on top of where a RecyclerView would be, and disappear once the data is finished loading It would look like: Can anyone help me out? I have the code which shows a TextView above the RecyclerView that…
fred jones
  • 245
  • 1
  • 2
  • 10
18
votes
6 answers

Overlaying the Action Bar not working

I was following official developer's guide to overlay actionbar. my style.xml is as following: