Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6619863
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:01:35+00:00 2026-05-25T21:01:35+00:00

I need to have a LinearLayout inside a SrollView and that LinearLayout must have

  • 0

I need to have a LinearLayout inside a SrollView and that LinearLayout must have a margin from the ScrollView. At first, the only way I could think of to solve that issue was having a LinearLayout inside another LinearLayout with the margins set on the this last layout. They wouldn’t work if they were set in the outer LinearLayout.

Example:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:fillViewport="true"
    android:background="@color/layout_color_green">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:background="@color/layout_color_yellow">
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_margin="10dp"
            android:orientation="vertical"
            android:background="@color/layout_color_blue">
        </LinearLayout>
    </LinearLayout>
</ScrollView>

enter image description here

My question is: Why do I need to do this?

If I had only one LinearLayout there would be no margins…

Example:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:fillViewport="true"
    android:background="@color/layout_color_green">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_margin="10dp"
        android:orientation="vertical"
        android:background="@color/layout_color_blue">
    </LinearLayout>
</ScrollView>

enter image description here

Then, searching for some similar issue, I found a few layouts which gave me the idea of using padding in the ScrollView instead of margin in the LinearLayout. This also solves my problem and I don’t need a LinearLayout inside another one. It’s a more elegant solution.

Still, I would like to understand why the simple margin inside the LinearLayout doesn’t work when inside a ScrollView. Because it does work fine if it’s not inside a ScrollView.

Anyone knows why?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T21:01:36+00:00Added an answer on May 25, 2026 at 9:01 pm

    I digged a little bit into the source code:

    ScrollView extends FrameLayout. This one has some margin issues itself and ScrollView is not even trying to solve that. The margins are basically ignored while measuaring.

    But in the end it doesn’t matter since you should be able to define a padding on the ScrollView itself (it’s an affirmation, didn’t try that). There should be no need for margin for a single child view.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a GridView inside of a LinearLayout inside of a ScrollView that pages
I really only need my ScrollView wrapped around 1 of the 3 LinearLayout s
I have a ScrollView with a LinearLayout inside an I'm adding TextViews. But I
I have need to select a number of 'master' rows from a table, also
I have need to return multiple results from a subquery and have been unable
I have need for a function pointer that takes two arguments and returns a
I need to have a layout that has a view above a set of
I have a custom component which extends LinearLayout, I need to execute certain statements
I need some help. In my android app I have a ViewFlipper that contains
I have a set of 10 image views that need to be set on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.