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

buttons below expanding scrollview

The layout I try to implement is (I think) pretty simple. One TextView expands depending on what is inside. Just below are two buttons (OK/Cancel). I can make the buttons stick to the bottom of the screen and that works fine. But I would like to…
Matthieu
  • 16,103
  • 10
  • 59
  • 86
16
votes
1 answer

Android Emulator doesn't Scroll down

I am creating a layout as follows and when I emulate it in the AVD. It doesn't Scroll down to see the conten below the fold.
Harsha M V
  • 54,075
  • 125
  • 354
  • 529
16
votes
1 answer

Passing focus from parent to children in Linear Layout

I have a nested series of linear layouts in my xml code. I want the first child of the parent (also a linear layout) to take focus. It does this if I set focusable to true. I would also like pass the focus onto the children of this layout (in order…
steemcb
  • 563
  • 1
  • 7
  • 19
16
votes
6 answers

Resources and layout direction rendered incorrectly only on Android 8.0 and above

I have a multilingual app with primary language English and secondary language Arabic. I am calling setLocale() in the onCreate() of every Activity in my app: public static void setLocale(Locale locale){ Locale.setDefault(locale); Context…
Yash Sampat
  • 30,051
  • 12
  • 94
  • 120
16
votes
3 answers

How can I prevent a TextView in a ConstraintLayout Chain from pushing other TextViews beyond their constraints while using layout_constrainedWidth?

My end goal is to have two single-line TextViews in a left-aligned, packed horizontal chain that allows both of them to grow to fill the remaining space, splitting it evenly if necessary, ellipsizing when there's not space. Visual Aid: And here's…
16
votes
5 answers

Bottom Navigation with fab

I am currently working with BottomNavigationView and FloatingActionButton. What i want to achieve is this below design: And what i have tried:
16
votes
5 answers

Navigate to fragment on FAB click (Navigation Architecture Components)

I have no idea how to, using the new navigation architecture component, navigate from my main screen (with a FloatingActionButton attatched to a BottomAppBar) to another screen without the app bar. When I click the fab I want my next screen…
16
votes
3 answers

Programmatically change the layout color of layout

I am trying to programatically change the layout color but of a relative layout (tried Linear layout but didn't change), but cannot change it. Also trying to debug the app doesn't help, there was not message related to my TAG. the application stood…
Sid
  • 1,145
  • 5
  • 17
  • 24
16
votes
5 answers

How to generate rounded square launcher icon android

I try to generate new launcher icon for my android project. I am taking png icon 512x512 and through Android Studio I am converting it New->Image Asset->(Launcher Icons Adaptive and legacy). It generates icon, but the size of radius of rounded…
yozhik
  • 4,644
  • 14
  • 65
  • 98
16
votes
2 answers

A grid layout of icon/text buttons

I am attempting to create a 3 x 3 grid of items. Each Item consists of an ImageView on top of a TextView. Unfortunately, I am having issues getting everything to play nicely. Here is my attempt to get 2 such items side by side. The text views…
Josh
  • 16,286
  • 25
  • 113
  • 158
16
votes
2 answers

Android Problems Converting ViewGroup with Children into Bitmap

I'm successfully converting a ViewGroup (RelativeLayout) into Bitmap using a Canvas. However, when the draw happens I only see the ViewGroup with its background drawable and not its children (two TextViews) who should be laid out within the…
Rob Holmes
  • 3,768
  • 1
  • 16
  • 19
16
votes
4 answers
16
votes
2 answers

How do I enable the rulers on Layout Editor?

I've seen some Layout Editors in Android Studio with a ruler on top and on the side for the Preview window and I'm trying to figure it out how to enable, any ideas? I'm using Android Studio 3.0.1 and I can't see them.
davisjp
  • 730
  • 1
  • 11
  • 24
16
votes
5 answers

why android studio show error of "Missing constraints in constraintlayout"?

picture This view is not constrained, it only has design time positions, so it will jump to (0,0) unless you add constraints The layout editor allows you to place widgets anywhere on the canvas, and it records the current position with design time…
16
votes
7 answers

How to set X axis labels in MP Android Chart (Bar Graph)?

This is with reference to the article : https://github.com/PhilJay/MPAndroidChart/wiki/Setting-Data under the heading Bar Graph.In the given code below: @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle…
Shubham Tunwal
  • 237
  • 1
  • 3
  • 11
1 2 3
99
100