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

Programmatically adding items to a relative layout

I have been searching everywhere for an answer to this question. I'm new to Android and attempting to add items to a relative layout programmatically through java instead of xml. I have created a test class to try it out but the items keep…
user597436
  • 173
  • 1
  • 1
  • 4
17
votes
4 answers

How to apply two different styles to one element in android?

I have a TextView and I want to apply a Style which I use for all TextView elements plus another style which I only use within a specific Activity. Is there any possibility to do that?
Bruiser
  • 11,767
  • 5
  • 34
  • 45
17
votes
2 answers

Custom TextInputLayout android

I am trying to create custom TextInputLayout. How can I create below custom TextInputLayout?
dreamfire
  • 427
  • 1
  • 5
  • 15
17
votes
7 answers

How to make option menu appear on bottom of the screen?

Here is what I am trying to implement: when people click on the menu on top right corner of a toolbar, an options menu appears on bottom of the screen. See picture below: I am not sure what method should I call for the item at the bottom. Can…
ken
  • 2,426
  • 5
  • 43
  • 98
17
votes
5 answers

How can I create an AttributeSet from a style.xml?

Here's my story: I got a custom ViewGroup that I want to create from code using a predefined style, my approach so far has been creating an AttributeSet object from a style.xml element, like so (warning, beware of the copy-paste code ahead): …
juanhawa
  • 183
  • 1
  • 6
17
votes
2 answers

Programmatically scroll to end of screen

I have implemented TapTargetView library to my app. After passing a certain element, I need to focus on the next view which is outside the screen at this moment: @Override public void onSequenceStep(TapTarget lastTarget) { if (lastTarget.id() ==…
Haze
  • 193
  • 1
  • 1
  • 7
17
votes
3 answers

Possible overdraw: Root element paints background with a theme that also paints a background

I have implemented clickable Recyclerview item and set android:background="?selectableItemBackground" for click effect but while inspecting code I found this lint issue. Lint warning : Possible overdraw: Root element paints background…
Pratik Popat
  • 2,891
  • 20
  • 31
17
votes
3 answers

Can't drag and drop a simple imageView in android studio

I'm trying to create a simple drag and drop image in android studio. I can get the image to drag around the screen, it disappears as soon as I release it. In the console, I get a "Reporting drop result: false" Here's my code: ImageView…
fmi
  • 512
  • 4
  • 14
17
votes
12 answers

Change Popup menu background color

NOTE: I have searched for an hour and tried all solutions already provided by stackoverflow. I am studying theme overlays. I have made a sample app, which opens a popup menu on clicking an action bar icon. Here is my styles.xml
mallaudin
  • 4,744
  • 3
  • 36
  • 68
17
votes
1 answer

How add item transparency inside RecyclerView when it's out of list border?

How make RecyclerView item disappear smoothly when it is going out of list border? See image below. All possible solutions highly appreciated! Note: Solution with View above RecyclerView which has gradient background (shadow imitation) does not…
17
votes
10 answers

Android studio layout xml not updating

I am using Android Studio latest version and recently facing a problem that, my layout xml Design view not getting updated rapidly if I have changed background from selector resource or changed the image resource background. I found that Rebuild…
Alex Chengalan
  • 8,211
  • 4
  • 42
  • 56
17
votes
4 answers

How to change hint text size without changing the text size in EditText

I have a EditText input field. I have added a hint in it. Now i want to change the size of hint text, but when i do this, it also effects the size of the text. Kindly guide me how to change the size of hint and text separately, and give different…
dev90
  • 7,187
  • 15
  • 80
  • 153
17
votes
5 answers

Add icon with title in CollapsingToolbarLayout

I am using CoordinatorLayout to get this effect : Here is the layout code:
17
votes
6 answers

Android : Cardview Background is turning to black on 4.1.2

I am using google cardView support library for my card functionality. It works well for kitkat and version up but however the background of card is set to black and padding/margins are not applied on device…
Sutirth
  • 1,217
  • 4
  • 15
  • 26
17
votes
6 answers

AppCompat DayNight theme not work on Android 6.0?

I am using the new Theme.AppCompat.DayNight added in Android Support Library 23.2 On Android 5.1 it works well. On Android 6.0, activity looks like using light theme, but dialog looks using dark theme. My Application class: public class…