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

Infinite scroll of finite items

I have a GridView that has items inside 5x50. I need to scroll them in all directions and instead of stopping when reached the end just start from the top/left. for example left-to-right scroll before scroll 1 2 3 4 5 6 7 8 9 10 after scroll to the…
16
votes
4 answers

Make ImageView have dark transparency

I want to add the transparent black color on top of the image and make it darker.
Karesh A
  • 1,731
  • 3
  • 22
  • 47
16
votes
2 answers

Android: remove shadow from bottom navigation

When placing a container below my bottom navigation, it is partly covered by the gray shadow from the navigation, even after adding content to the container. How do I remove the shadow?
tmbz
  • 163
  • 1
  • 4
16
votes
2 answers

Android - Switch between front and back camera while recording a video

I am trying to implement Custom Camera to record a video. I have followed This sample and it is working fine. Now, i want to add "Switch Camera" functionality over a Button click. It should be able to Switch between Front/Back Camera even while the…
iMDroid
  • 2,108
  • 1
  • 16
  • 29
16
votes
1 answer

Using ConstraintLayout in creating a fragment

I'm wondering whether it's possible to create a fragment layout using ConstraintLayout or not!? Is it a proper approach? or is there any standard root element for creating a fragment?
16
votes
4 answers

Different tab width for TabLayout

I'm using TabLayout & ViewPager. I am trying to change the size of the Tab, like Whatsapp (camera icon). The size of the three Tabs is equal, but the Tab of the camera is smaller. In every attempt I make the size of the Tabs remains the same (equal…
16
votes
2 answers

Why we use ViewTreeObserver#addOnGlobalLayoutListener()

Why do we use ViewTreeObserver, please can anyone explain it? In below code creditsView is TextView object. By this whole code I understand that "this is to hide some text based on condition", but only thing is why we are using…
16
votes
4 answers

setRecycledViewPool method in RecyclerView

I am trying to understand what the setRecycledViewPool method actually does along with the RecyclerView in the following line of code where mrecyclerView is a RecyclerView object: mrecyclerView.setRecycledViewPool(new…
16
votes
3 answers

How do you create an app that only allows horizontal orientation?

I'm currently creating a side-scroller style game for my final year project for my degree. I'm just wondering how you make the menu designed for when the phone is in horizontal orientation display, even when the phone is held in it's vertical…
KieH22
  • 161
  • 1
  • 1
  • 3
16
votes
1 answer

Can A WindowBackground Be Positioned Below The Status Bar & Above The Navigation Bar?

Based on this tutorial and this answer, which also references this other tutorial, using a theme's android:windowBackground along with a appears to be the most approved method of creating an Android Splash Screen Using this technique…
Forrest Bice
  • 602
  • 5
  • 16
16
votes
1 answer

Android shape border with gradient and middle transparent

I need to create a round corner border, where border with gradient.enter link description here is working.But My page is using a image as background which is also with gradient. I need to show background image from middle of the filed. I want to…
Suman
  • 1,307
  • 15
  • 32
16
votes
4 answers

How to overcome this item padding in navigation drawer?

I check out all the question and also google a lot I just want to remove this padding between each item in navigation view. Help me to sort out this problem thanks in advance. This is the code of my main_drawer
Abhishek Bhardwaj
  • 1,164
  • 3
  • 14
  • 39
16
votes
5 answers

How to make tab title alignment to left in TabLayout in Android

I can't seem to align my tab titles to the left, inside my TabLayout. At the moment, the titles are centered. Here is what I want to achieve. And this is what I have at the moment. The code I'm using is as…
Naman
  • 161
  • 1
  • 1
  • 4
16
votes
1 answer

ViewDragHelper - Child layout changes ignored while dragging

I'm trying to apply margin updates or animations to a child view which parent is dragged using a ViewDragHelper. However the updated layout properties have no effect and are not rendered while the view is dragged. Everything from adding and removing…
Richard
  • 14,427
  • 9
  • 57
  • 85
16
votes
2 answers

RecyclerView layoutmanager for changing row and column span

I am looking to create the following layout (red sqaures does not really have to be squares, a custom fixed height is also fine). The layout seems very simple yet I did not find a layout manager which suits my needs. I tried the…
Brianvdb
  • 666
  • 1
  • 6
  • 16
1 2 3
99
100