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:

57356 questions
15
votes
1 answer

Documentation for styles in android resources

I tried to add a documentation to some styles in my code. The issue is, that android studio doesn't link the documentation directly to a usage of the style. I mean, the simple comment doesn't create my desired documentation for the…
Kenny Seyffarth
  • 1,016
  • 11
  • 26
15
votes
3 answers

Android: Draw Background with no GPU OverDraw like Whatsapp

In order to improve app performance, I encounter GPU Overdraw problem. According to Romain Guy's Article, here are the basic Colors: No color means there is no overdraw. The pixel was painted only once. In this example, you can see that the…
Aexyn
  • 1,194
  • 2
  • 12
  • 30
15
votes
2 answers

How to call layout xml from another module

I am setting ContentView in MainActivity as setContentView(R.layout.activity_main); I have other module in package as well, for that module I defined in gradle file apply plugin: 'com.android.library' This once also has…
15
votes
1 answer

add Layout programmatically inside another one

I have an xml file (option_element.xml) that contains a ImageView and a TextView
giozh
  • 8,808
  • 27
  • 89
  • 163
15
votes
1 answer

android lollipop animation glitch

I have a strange behaviour with the default layout animation in devices running Android 5 (Lollipop). I am using an activity with multiple Fragments which are replaced at runtime using the default fragment manager. When replacing the old fragment, i…
15
votes
4 answers

EditText without line at bottom

I want to make my edit text field without the line at the bottom, like in this picture Right now my edit text looks like this How can I do it?
Sartheris Stormhammer
  • 2,366
  • 7
  • 31
  • 71
15
votes
1 answer

Android How to edit the Action bar menu from Fragment

I created an App that uses Fragment. From my MainActivity I set the ActionBar. But in one of my Fragment I need to modify the action icons and on click. So With the code below, when I load the my Fragment, it still display the action bar menu from…
Thiago
  • 9,554
  • 11
  • 68
  • 97
15
votes
2 answers

Is there a way to check if android WindowManager already contains a view?

When I try to do a WindowManager.removeView(), E/AndroidRuntime( 2445): java.lang.IllegalArgumentException: View=android.widget.LinearLayout{41a03700 V.E..... ......I. 0,0-0,0} not attached to window manager E/AndroidRuntime( 2445): at…
likejudo
  • 2,611
  • 6
  • 39
  • 83
15
votes
1 answer

Clipped button doesn't receive touch input

I have a FAB that resides in between two layouts. Using negative margin alongside with android:clipChildren and android:clipToPadding both set to false I'm able to produce this pleasantly placed little button: Now, the problem is that the bottom…
Hadi Satrio
  • 4,102
  • 2
  • 21
  • 41
15
votes
6 answers

How to prevent ScrollView from intercepting click/touch events of the view behind it?

I have a ScrollView and an ImageView inside a FrameLayout. The ImageView is behind the scroll view My ScrollView have a transparent space (LinearLayout s_layout_transparent with 925px height). So my ImageView can be seen through this transparent…
NghiaDao
  • 383
  • 1
  • 3
  • 14
15
votes
3 answers

Android: Placing ImageView on overlap between layouts

I am trying to place an ImageView on the overlap point between two layouts. In the picture below, my goal would be to place the ImageView where the white square is. NOTE: The overlap point will not necessarily be centered vertically as shown…
Daiwik Daarun
  • 3,292
  • 4
  • 28
  • 54
15
votes
5 answers

Default inputType of EditText in android

Suppose I have an EditText in my layout. We can set the inputType for this EditText…
Nidheesh
  • 612
  • 1
  • 6
  • 17
15
votes
2 answers

android - use camera without surfaceview or textureview

I have been trying to figure out if there is a way to use camera to take either video/pictures without defining surfaceview or textureview. I found this link: Use Android Camera without surface View I used this trick with textureview on my nexus…
pree
  • 2,057
  • 6
  • 32
  • 50
15
votes
3 answers

Set the width of relativelayout 1/3 the width of the screen?

I have a layout like below. Now, I don't want to set the width of relative layout to fixed 240 dp. I want to set the width of the relative layout to 1/3 the width of the screen. Is it possible to do that in the xml file. If it is impossible, how can…
Kelvin Tan
  • 900
  • 1
  • 11
  • 31
15
votes
7 answers

White background when Android app start up

Every when my app starts up, there's a white background displays in a short time. Despite of using splash screen, the problem is still exists. I would like to set the start up screen to black instead of white as default! This is my splash's screen…
cxphong
  • 797
  • 1
  • 8
  • 17
1 2 3
99
100