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

Android zoomable/scrollable ImageView with overlays

I would like to display an image (including scroll and zoom functionality). Additionally, I need to add some overlays to the image dynamically. The overlays are in a relationship to the content within the image. If the user scrolls, the overlays…
18
votes
9 answers

Reverse the direction of a LinearLayout

How can I reverse the direction of a linear layout? for example, if my layout is [view1, view2, view3] I want to create [view3, view2, view1]. My goal is to inflate a left and a right handed instances from one XML layout.
ZeroEric
  • 371
  • 1
  • 4
  • 7
18
votes
9 answers

Android: How to find views by type

Ok so I have a layout xml similar to the following example:
Neil
  • 7,861
  • 4
  • 53
  • 74
18
votes
2 answers

How to fill the empty spaces with content below the Image in android

I have one ImageView and a TextView in my xml layout. I want to show the text below that i got by webservice on the right side of the ImageView. Can i show that text by using that one TextView ? I tried to give android:singleLine="false" in xml…
Victor
  • 893
  • 3
  • 11
  • 21
18
votes
7 answers

Custom Layout that rounds the corners of its content

I would like to create a generic ViewGroup which can then be reused in XML layouts to round the corners of anything that is put into it. For some reason canvas.clipPath() doesn't seem to have an effect. What am I doing wrong? Here is the Java…
P Varga
  • 19,174
  • 12
  • 70
  • 108
18
votes
1 answer

Android Column GridView, variable width like GooglePlus App

So like most we have all used/seen the Google Plus App. What interests me is the ColumnGridView they have developed, which not only does variable width, but variable height, seems that based on content will happily show the best space for the…
Chris.Jenkins
  • 13,051
  • 4
  • 60
  • 61
18
votes
4 answers

EditText : set number of characters programmatically

I have a EditText , and I would like to restrict the number of characters which could be inputted in this EditText, and make this restriction programmatically, how to do it? For example, say I would like to restrict it to only allow 10 characters.
john123
  • 589
  • 3
  • 6
  • 16
18
votes
4 answers

Replacement for the linearLayout weights mechanism

Background: Google suggests to avoid using nested weighted linearLayouts because of performance. using nested weighted linearLayout is awful to read, write and maintain. there is still no good alternative for putting views that are % of the…
18
votes
7 answers

Dynamic vs XML layout in Android?

I'm new to Android development and have started creating my own UI. I see that you can either create it dynamically something like this (Dynamic Layouts): @Override public void onCreate(Bundle savedInstanceState) { …
David Kroukamp
  • 36,155
  • 13
  • 81
  • 138
18
votes
2 answers

Have horizontal RadioButtons wrap if too long for screen

So I have the following radiobuttons. I want to have them display like this: However this occurs: How I can get it to display like above? I can move in the GUI editor in Eclipse it but it removes the RadioButton from the RadioGroup!Within the…
TheRealKingK
  • 829
  • 7
  • 14
18
votes
7 answers

Android Countdown Timer to Date

I am trying to make a countdown timer for a game/date in android. I want to create a timer that displays the days, hours, minutes, and seconds to a date I specify with a final variable. The timer then sets text views to show the days, hours,…
ultimatenirvana
  • 451
  • 3
  • 5
  • 12
18
votes
2 answers

Android Master Detail Flow Example

I'm trying to implement a user interface like above and looking for a good tutorial to or code sample to learn it. Can someone help me to get this done
SLM
  • 839
  • 3
  • 14
  • 31
18
votes
4 answers

Common Header in different activities using BaseActivity in android

I want write code once and use in different activities. I have created a Base Activity class for that . Also the header of all the layouts in different activities are same. I have done that with the help of the tag. Now the…
ADB
  • 567
  • 2
  • 5
  • 20
18
votes
5 answers

Android: Samsung Galaxy S3 screen size for layout

Is anyone out there testing on a Samsung Galaxy S3 yet? Specifically, does it have what is considered a large or normal screen for layout purposes? I have the Galaxy Nexus and it takes normal layouts, but I read the Galaxy Note is considered a…
rustyWhitefeather
  • 400
  • 1
  • 3
  • 12
18
votes
3 answers

Android: Rotate animation get back to its real state after finishing the animation?

I am going to rotate the image in My app. All Works fine with the Rotation. But while i rotation animation get finish the Image wil return to its previous position. I want is to remain that image to that rotated state and not to get it back to its…
Shreyash Mahajan
  • 23,386
  • 35
  • 116
  • 188