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

Hide AppBar when scrolling down

I have an AppBar and a horizontal linearlayout (which includes an edit text and two imagebuttons) and other things in my layout. When user scrolls down, I want AppBar(actually, the Toolbar to hide. This is what I have tried, the appbar isn't hiding…
jason
  • 6,962
  • 36
  • 117
  • 198
17
votes
4 answers

LinearLayout inside a ToolBar is not matching parent

I put a LinearLayout1 in the ToolBar.Then another 5 LinearLayouts in the LinearLayout1. Each child LinearLayout has an ImageView. Here my problem is that the LinearLayout1 is not matching parent width.That I have showed in the image(in red circle).…
17
votes
9 answers

How to change indicator of tablayout to top from bottom?

I want to change indicator of tablayout from bottom to top. my code activity_tab.xml
17
votes
6 answers

how do I highlight the searched text in my search filter?

I am trying to do a search such that all the "visible" search letters should be highlighted. I tried using spannable but that didn't do the trick, maybe I wasnt doing it right? based on this: Highlight searched text in ListView items How do i get to…
user2386226
17
votes
9 answers

Changing the drawable size inside a button

I want to create a Button like this: Here is my code:
17
votes
5 answers

How to scroll horizontal RecyclerView programmatically?

I have a horizontal RecyclerView and two button (Next,Previous) as shown in the image below. so i need to move to the next item or position by use these buttons , i know about method called scrollTo but i don't know how does it work
17
votes
2 answers

How dismiss parent padding in children element

I have FrameLayout and for most fragments the parrent padding is good. But I have especial fragment which must not contain the padding.
Coffeeman
  • 285
  • 1
  • 6
  • 17
17
votes
2 answers

How to fill RecyclerView Adapter with Firebase

I made a lot of research, but I couldn't find any resource how to use Recycler View with Firebase(or vice versa) There is one Firebase list adapter which extends from BaseAdapter. I found it in Firebase Chat application. Here is the…
Adem İlhan
  • 1,460
  • 3
  • 16
  • 26
17
votes
1 answer

How do I Change the Alignment of Toolbar Child Views

I have a toolbar and I want to add an ImageView to its layout in xml. I want it to align right, instead of the default align left. According to the documentation: The application may add arbitrary child views to the Toolbar. They will appear at…
Jon
  • 9,156
  • 9
  • 56
  • 73
17
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,212
  • 2
  • 13
  • 30
17
votes
4 answers

How to override RTL support on a layout in Android

I set android:supportsRtl="true" in the tag in AndroidManifest.xml, but I need to force one of the views to be left-to-right nonetheless, even when the language of the interface is Hebrew or Arabic. How can I force a specific view to…
Ilya Kogan
  • 21,995
  • 15
  • 85
  • 141
17
votes
2 answers

FragmentTabHost - No tab known for tag null

Few days ago I implemented TabHostFramgent in a Fragment with a NavigationDrawer, and I faced with a problem that is the following error : java.lang.IllegalStateException: No tab known for tag null The thing is that all works perfectly since my…
17
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
  • 9,868
  • 30
  • 102
  • 183
17
votes
3 answers

Adding an ActionBar to the Default Google Maps Activity Template in Android Studio

I've been able to add all of my markers to my map, using locations provided by my API, but I've been unable to add an ActionBar. As mentioned, I am using the Android Studio "Google Maps Activity" template. How can I go about adding an ActionBar to…
17
votes
4 answers

How to increase space between text and it's underline in TextView Android?

I want to increase space between text and it's underline. I can change line height but I don't change height between text and it's underline.How can I do this ? private static final String FONTH_PATH = "fonts/Brandon_bld.otf"; ... selectTextView =…
buraktemzc
  • 390
  • 1
  • 6
  • 19