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

What is android:layout_marginStart

I would like to add some space between the left display border and an ImageView. Android SDK made me aware of "android:layout_marginStart". Consider adding android:layout_marginStart="10dp" to better support right-to-left layouts Why should I use…
null
  • 1,369
  • 2
  • 18
  • 38
17
votes
3 answers

Android Performance : Adding view programmatically vs setting view to GONE/VISIBLE

I'm working in a project that requires to inflate a simple tutorial View when the user opens the app for the first time. I'm trying to do it "the right way", and I'm wondering about performance issue. Currently, I have in my layout a view sets to…
MagicMicky
  • 3,819
  • 2
  • 37
  • 53
17
votes
1 answer

Are the "GONE" views inflated?

I have a huge XML layout, with many Relative / Linear layouts, and what I'm doing now is to hide all the layouts I don't need with setVisibility (View.GONE) and change their visibility when needed. My question is : is this method sufficient? are the…
user1079425
17
votes
9 answers

Android support v4 SwipeRefreshLayout empty view issue

SwipeRefresh is not working after setting an empty view for listview which is the only child of a SwipeRefresh layout. How to solve this issue?
Dinesh
  • 965
  • 2
  • 11
  • 23
17
votes
8 answers

Android - SwipeRefreshLayout import not found

I'm trying to implement the new RefreshLayout widget but it seems my eclipse doesn't recognize the import I need to set. I used this guide to get started: Swipe to refresh GUIDE And here is where it all started: Android dev - Swipe to refresh My…
Niels
  • 659
  • 2
  • 7
  • 15
17
votes
9 answers

eclipse can't find android.support.v4.widget.SwipeRefreshLayout

Even after clicking on Add Support Library and choosing version 19, eclipse still can't find android.support.v4.widget.SwipeRefreshLayout. Does anyone know how to get this to work? I am…
Katedral Pillon
  • 14,534
  • 25
  • 99
  • 199
17
votes
8 answers

Error inflating class android.support.v4.widget.drawerlayout

I've done numerous searches on this topic. I have done the following: Made sure the support library was up to date via the SDK Manager. Went into the build path and the order and export tab to make sure dependencies were checked. Cleaned my…
user3241191
  • 505
  • 2
  • 5
  • 12
17
votes
7 answers

android.view.inflateexception binary xml file line #1 error inflating class android.widget.relativeLayout

I am new in android. I just made a new layout with one text bar and 2 buttons but it didn't work, I am posting the stack trace and my relative layout file any idea about this? I saw the same question there which says to decrease the draw able size.…
jazz b
  • 437
  • 1
  • 6
  • 15
17
votes
2 answers

How to lock fragment orientation without locking activity orientation?

I have a specific use case where I want a fragment to be locked in portrait mode, but still rotate the activity (and/or other fragments visible in the same activity). Is it possible to do that? All the solutions to locking a fragment orientation…
17
votes
2 answers

How do I preserve the state of a selected spinner/dropdown item on orientation change?

I am using a spinner dropdown in my code , in which I have 4 to 5 dynamically populated values, say if I have "apples" set to default and I select "oranges" from the dropdown and rotate my screen to landscape from portrait, it goes back to default…
17
votes
1 answer

Possible to inflate an XML layout in a Service? (Android)

I want to inflate an xml layout in a service. How do you do this? I tried to use inflater and Window Manager but I think it don't work. Any tactics on this? Thanks.
The One
  • 1,085
  • 6
  • 13
  • 25
17
votes
4 answers

Include same layout multiple times

I have a common layout (common.xml) which I want to include many times in another layout (layout_a.xml). But it only shows me just one time. Why? common.xml
user2761885
  • 327
  • 1
  • 7
  • 13
17
votes
10 answers

Listview same height as content

I used custom listview . Content comes from dynamic I want to same listview height same as content. I used wrap_content but this does not help If I remove scrollview then its work Code. "The vertically scrolling ScrollView should not contain another…
Nick
  • 351
  • 3
  • 7
  • 22
17
votes
4 answers

Android ScrollView fillViewport not working

I have a simple layout with a name on the top, and a button which I want to be at the bottom of the screen, or beyond that in case I add more items. So I am using a ScrollView with a LinearLayout as follows:
17
votes
4 answers

Android grow LinearLayout using animation

I am trying to use animation to make a layout appear on screen. The idea is that layout will start with height of 0 and grow to 100%. I have real troubles with this and need some assistance. For some reason no animation is performed. Here is my…
svager
  • 769
  • 5
  • 13
  • 32