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

NullPointerException at android widget ArrayAdapter createViewFromResource

I am a new to android ArrayAdapters and I am facing a null pointer exception when populating my ListView. The data which I used to populate the listview is not null, I had checked that. Also the whole thing is working fine on first load, but once I…
18
votes
1 answer

Android Studio layout previews for Listview + Gridview

Is there a way to get Android Studio's layout preview screen to populate a GridView or ListView with placeholder views of the actual runtime layout? In other words, I don't want to see a grid of "Item 1/ Sub Item 1" views, I want to be able to set…
sigmabeta
  • 1,174
  • 1
  • 12
  • 28
18
votes
7 answers

Unable to start uiautomatorviewer

I have : Android SDK Tools, Revision 22 Android SDK Platform, API 18 I go to /tools/ , I see there is one file named "uiautomatorviewer", I execute command uiautomatorviewer from terminal under the above path, however I got the…
Mellon
  • 37,586
  • 78
  • 186
  • 264
18
votes
4 answers

Check if ScrollView is higher than screen / scrollable

How can I check if a ScrollView is higher than the screen? When the content of a ScrollView fits on the screen, the ScrollView isn't scrollable, when it's contents exceed the screen height it's scrollable. How can I check the condition of a…
fweigl
  • 21,278
  • 20
  • 114
  • 205
18
votes
7 answers

Android findViewById() in Custom View

I've written my custom View and i want to update some other views after interacting with my custom view. Main Layout:
Jilberta
  • 2,836
  • 5
  • 30
  • 44
18
votes
5 answers

How to feed DatePicker widget with other calendar sytems?

Is there anyway to use DatePicker widget with other calendar systems ? I need a picker for Jalali (Persian) Calendar system, but i dont know how to feed DatePicker with my data. I've studied methods related to DatePicker but couldn't find anything…
Nevercom
  • 840
  • 3
  • 14
  • 38
18
votes
5 answers

LinearLayout with two children of equal width

I'm having some issues getting two children of a LinearLayout to have the same width. This is what I am getting: And here is my layout xml for the grey box:
boz
  • 4,891
  • 5
  • 41
  • 68
18
votes
9 answers

Layout preview not working in Android Studio

I ported an android project from Eclipse to Android Studio. The project builds just fine. However I am not able to see any layout preview. When I go to the Design tab of a layout I get a Loading Configuration... message that never goes away (see…
Thomas Kaliakos
  • 3,274
  • 4
  • 25
  • 39
18
votes
8 answers

Get the screen height in Android

How can I get the available height of the screen in Android? I need to the height minus the status bar / menu bar or any other decorations that might be on screen and I need it to work for all devices. Also, I need to know this in the onCreate…
Dan Bray
  • 7,242
  • 3
  • 52
  • 70
18
votes
8 answers

Change Relative layout width and height dynamically

Hi i am using following layout structure inside LinearLayout
Vikas Panwar
  • 399
  • 1
  • 3
  • 14
18
votes
2 answers

Is it possible to always show the action bar when using adjustPan as soft input mode?

In my application I have a ListView with a footer that contains a custom view with an EditText inside. At the top sits an action bar. The activity currently uses SOFT_INPUT_ADJUST_RESIZE (adjustResize) as soft input mode and does not close the…
18
votes
2 answers

How to center image vertically in this RelativeLayout

I have below layout which basically show "messages" as bubble slimier to built-in "Messages". I just need to show also an arrow image on the right, th eimage is shown, but I need it to be centered vertically. I tried to add "…
user836026
  • 10,608
  • 15
  • 73
  • 129
18
votes
6 answers

Layout folders for Google Nexus 7 and 10

I am developing an application for google nexus 7 and 10. But there is a problem. I don't know which layout folder should be used for 7 and 10.
User42590
  • 2,473
  • 12
  • 44
  • 85
18
votes
5 answers

Using Android Drag and Drop framework in My custom Launcher app

I am trying to develop custom launcher app (with unlimited number of home pages)and i need to implement Drag and Drop as done in Launcher2(android 4.2). So i found two approaches 1) Drag and Drop framework 2) Use the android launcher2 way like…
manjusg
  • 2,275
  • 1
  • 22
  • 31
18
votes
3 answers

getMeasuredHeight() of TextView with wrapped text

I'm trying to determine the height of a TextView before it is drawn. I'm using the following code to do that: TextView textView = (TextView) findViewById(R.id.textview); textView.setText("TEST"); int widthSpec =…
nhaarman
  • 98,571
  • 55
  • 246
  • 278