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

How to prepare layout,drawable folders for 7",10" android tablets for both landscape and portrait?

I have prepared my drawables for 7" tablets as (Nexus 7) drawable-large-hdpi-port layout-large-hdpi-port I am getting errors while doing this. I didnt understand where I am doing wrong. I want to prepare layouts for both landscape and portrait…
user2376732
  • 379
  • 1
  • 5
  • 14
17
votes
4 answers

set shape background to transparent in android

I have a shape drawable that I want to use as a background. I want the shape to be transparent. But so far it's not. How do I do that? Here is what I have:
Cote Mounyo
  • 13,817
  • 23
  • 66
  • 87
17
votes
4 answers

Add Icons to Android Navigation Drawer?

I have scoured the web for an answer to this question but cannot seem to find one, even in the official Android documentation. I am in the process of creating an app that implements Android's new Navigation Drawer layout. Documentation of this…
bean
  • 1,244
  • 3
  • 13
  • 20
17
votes
5 answers

Android arrange layout with height as percentage

I am very new to android and practicing. I am trying to design a screen. which will contain a background image and a floating container with sliding menus. ( For more details please find the attached image ) My layout consists of a background image,…
ramesh
  • 4,008
  • 13
  • 72
  • 117
17
votes
2 answers

How to Debug Custom View in ADT's Graphical Layout Editor

How do I debug a Custom View in the Graphical Preview of a Layout XML using the ADT Eclipse plugin? I wrote a custom view, put it in a layout XML, and I can preview it in the ADT Graphical Layout Editor. I can view my custom view like how the…
Pang
  • 9,564
  • 146
  • 81
  • 122
17
votes
6 answers

Android CalendarView slowing down layout

This is driving me crazy. I have a fragment in my Android app which is laid out using a RelativeLayout. Problem is that for some reason it takes ages to render, about 5 seconds just to load about 4 elements on screen. One of the elements is a…
17
votes
7 answers

How to Show Circular Text using TextView in Android

I want to show text with circular shape in my android application.I know it is done with custome textview but can some buddy give me proper code.I am also attaching image which type of look i want.
Rishabh Agrawal
  • 861
  • 2
  • 15
  • 25
17
votes
1 answer

action bar behavior when android:targetSdkVersion is 16

I am trying to implement an action bar with tabs as navigation options. To do that I select the "Tabs+Swipe" option in the "New Blank Activity" section of the "New Android App" wizard as shown below. Now, in the android manifest,…
17
votes
12 answers

Text size with different resolution

i am using a galaxy tab 1, 7inch hdpi and a galaxy tab plus, 7 inch hdpi but more resolution, and in my application, the text can be read fine in galaxy tab but in galaxy tab plus there are too much small. Im using sp in font size and layout-large.…
colymore
  • 11,776
  • 13
  • 48
  • 90
17
votes
2 answers

Programmatically set attribute AlignParentRight to button in RelativeLayout is not working?

I try to programmatically set the attribute AlignParentRight to button in RelativeLayout but the program crashes with a NullPointerException. Here my code: //add horizontal realative layout RelativeLayout layouth = new…
Mokkapps
  • 2,028
  • 9
  • 42
  • 67
17
votes
7 answers

Android - Showing Phonebook contacts and selecting one

How can I show the list of contacts in phonebook on a click of a button and then select one of the contacts from it and then retrieve its contact number? I don’t want to make my custom list. Is there a way to use Android's built-in functionality?
mdanishs
  • 1,996
  • 8
  • 24
  • 50
17
votes
3 answers

FrameLayout to RelativeLayout ClassCastException even if there is no FrameLayout used

In my application, I have a layout which has a RelativeLayout to which I want to set margins at runtime programmatically. But when I do that, it gives me ClassCastException saying FrameLayout can not cast to RelativeLayout. I don't have any…
17
votes
6 answers

RelativeLayout add rule "RelativeLayout.LEFT_OF" not working

I have a relativeLayout like below:
dreamtale
  • 2,905
  • 1
  • 26
  • 38
17
votes
2 answers

Set RelativeLayout child to fill unused space

I have this layout:
artem
  • 16,382
  • 34
  • 113
  • 189
17
votes
5 answers

Adding "section dividers" to my layout?

The Android Design - Lists page describes "section dividers". I'm aware you can use addHeaderView() a ListView for a similar effect. I would like to use a "section divider" without a ListView, but rather a LinearLayout. In the screenshot below, I'm…
gak
  • 32,061
  • 28
  • 119
  • 154