Madalitso Phiri
Madalitso Phiri

Reputation: 25

Layout issue with my scrolling activity

I'm working on an android project and I added a scrolling activity. There's a portion of the lower end of the screen that takes the colour of the background and makes everything look untidy.This is how it looks. How do i fix this? I would like the mid portion to extend to the bottom of the screen, I tried everything changing height, matching to the parent. Nothing worked.Your help is much appreciated! Thanks. Code is below.

<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context=".ScrollingActivity"
tools:showIn="@layout/activity_scrolling"
android:background="@drawable/backgnd"
android:layout_marginRight="24dp"
android:layout_marginLeft="24dp">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal"
        android:baselineAligned="false">

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_margin="@dimen/text_margin"
            android:layout_weight="1"
            android:text="This is a generic message" />

        <Button
            android:layout_width="48dp"
            android:id="@+id/button"
            android:layout_height="match_parent"
            android:scaleType="centerCrop"
            android:background="@drawable/play" />

    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal"
        android:baselineAligned="false">

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_margin="@dimen/text_margin"
            android:layout_weight="1"
            android:text="This is a generic message" />

        <Button
            android:layout_width="48dp"
            android:id="@+id/button1"
            android:layout_height="match_parent"
            android:scaleType="centerCrop"
            android:background="@drawable/play" />


    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal"
        android:baselineAligned="false">

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_margin="@dimen/text_margin"
            android:layout_weight="1"
            android:text="This is a generic message" />

        <Button
            android:layout_width="48dp"
            android:id="@+id/button2"
            android:layout_height="match_parent"
            android:scaleType="centerCrop"
            android:background="@drawable/play" />


    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal"
        android:baselineAligned="false">

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_margin="@dimen/text_margin"
            android:layout_weight="1"
            android:text="This is a generic message" />

        <Button
            android:layout_width="48dp"
            android:id="@+id/button3"
            android:layout_height="match_parent"
            android:scaleType="centerCrop"
            android:background="@drawable/play" />


    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal"
        android:baselineAligned="false">

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_margin="@dimen/text_margin"
            android:layout_weight="1"
            android:text="This is a generic message" />

        <Button
            android:layout_width="48dp"
            android:id="@+id/button4"
            android:layout_height="match_parent"
            android:scaleType="centerCrop"
            android:background="@drawable/play" />


    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal"
        android:baselineAligned="false">

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_margin="@dimen/text_margin"
            android:layout_weight="1"
            android:text="This is a generic message" />

        <Button
            android:layout_width="48dp"
            android:id="@+id/button5"
            android:layout_height="match_parent"
            android:scaleType="centerCrop"
            android:background="@drawable/play" />


    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal"
        android:baselineAligned="false">

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_margin="@dimen/text_margin"
            android:layout_weight="1"
            android:text="This is a generic message" />

        <Button
            android:layout_width="48dp"
            android:id="@+id/button6"
            android:layout_height="match_parent"
            android:scaleType="centerCrop"
            android:background="@drawable/play" />


    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal"
        android:baselineAligned="false">

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_margin="@dimen/text_margin"
            android:layout_weight="1"
            android:text="This is a generic message" />

        <Button
            android:layout_width="48dp"
            android:id="@+id/button7"
            android:layout_height="match_parent"
            android:scaleType="centerCrop"
            android:background="@drawable/play" />


    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal"
        android:baselineAligned="false">

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_margin="@dimen/text_margin"
            android:layout_weight="1"
            android:text="This is a generic message" />

        <Button
            android:layout_width="48dp"
            android:id="@+id/button8"
            android:layout_height="match_parent"
            android:scaleType="centerCrop"
            android:background="@drawable/play" />


    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal"
        android:baselineAligned="false">

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_margin="@dimen/text_margin"
            android:layout_weight="1"
            android:text="This is a generic message" />

        <Button
            android:layout_width="48dp"
            android:id="@+id/button9"
            android:layout_height="match_parent"
            android:scaleType="centerCrop"
            android:background="@drawable/play" />


    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal"
        android:baselineAligned="false">

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_margin="@dimen/text_margin"
            android:layout_weight="1"
            android:text="This is a generic message" />

        <Button
            android:layout_width="48dp"
            android:id="@+id/button10"
            android:layout_height="match_parent"
            android:scaleType="centerCrop"
            android:background="@drawable/play" />


    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal"
        android:baselineAligned="false">

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_margin="@dimen/text_margin"
            android:layout_weight="1"
            android:text="This is a generic message" />

        <Button
            android:layout_width="48dp"
            android:id="@+id/button11"
            android:layout_height="match_parent"
            android:scaleType="centerCrop"
            android:background="@drawable/play" />


    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal"
        android:baselineAligned="false">

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_margin="@dimen/text_margin"
            android:layout_weight="1"
            android:text="This is a generic message" />

        <Button
            android:layout_width="48dp"
            android:id="@+id/button12"
            android:layout_height="match_parent"
            android:scaleType="centerCrop"
            android:background="@drawable/play" />


    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal"
        android:baselineAligned="false">

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_margin="@dimen/text_margin"
            android:layout_weight="1"
            android:text="This is a generic message" />

        <Button
            android:layout_width="48dp"
            android:id="@+id/button13"
            android:layout_height="match_parent"
            android:scaleType="centerCrop"
            android:background="@drawable/play" />


    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal"
        android:baselineAligned="false">

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_margin="@dimen/text_margin"
            android:layout_weight="1"
            android:text="This is a generic message" />

        <Button
            android:layout_width="48dp"
            android:id="@+id/button14"
            android:layout_height="match_parent"
            android:scaleType="centerCrop"
            android:background="@drawable/play" />


    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal"
        android:baselineAligned="false">

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_margin="@dimen/text_margin"
            android:layout_weight="1"
            android:text="This is a generic message" />

        <Button
            android:layout_width="48dp"
            android:id="@+id/button15"
            android:layout_height="match_parent"
            android:scaleType="centerCrop"
            android:background="@drawable/play" />


    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal"
        android:baselineAligned="false">

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_margin="@dimen/text_margin"
            android:layout_weight="1"
            android:text="This is a generic message" />

        <Button
            android:layout_width="48dp"
            android:id="@+id/button16"
            android:layout_height="match_parent"
            android:scaleType="centerCrop"
            android:background="@drawable/play" />


    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal"
        android:baselineAligned="false">

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_margin="@dimen/text_margin"
            android:layout_weight="1"
            android:text="This is a generic message" />

        <Button
            android:layout_width="48dp"
            android:id="@+id/button17"
            android:layout_height="match_parent"
            android:scaleType="centerCrop"
            android:background="@drawable/play" />


    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal"
        android:baselineAligned="false">

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_margin="@dimen/text_margin"
            android:layout_weight="1"
            android:text="This is a generic message" />

        <Button
            android:layout_width="48dp"
            android:id="@+id/button18"
            android:layout_height="match_parent"
            android:scaleType="centerCrop"
            android:background="@drawable/play" />


    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal"
        android:baselineAligned="false">

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_margin="@dimen/text_margin"
            android:layout_weight="1"
            android:text="This is a generic message" />

        <Button
            android:layout_width="48dp"
            android:id="@+id/button19"
            android:layout_height="match_parent"
            android:scaleType="centerCrop"
            android:background="@drawable/play" />


    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal"
        android:baselineAligned="false">

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_margin="@dimen/text_margin"
            android:layout_weight="1"
            android:text="This is a generic message" />

        <Button
            android:layout_width="48dp"
            android:id="@+id/button20"
            android:layout_height="match_parent"
            android:scaleType="centerCrop"
            android:background="@drawable/play" />


    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal"
        android:baselineAligned="false">

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_margin="@dimen/text_margin"
            android:layout_weight="1"
            android:text="This is a generic message" />

        <Button
            android:layout_width="48dp"
            android:id="@+id/button21"
            android:layout_height="match_parent"
            android:scaleType="centerCrop"
            android:background="@drawable/play" />


    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal"
        android:baselineAligned="false">

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_margin="@dimen/text_margin"
            android:layout_weight="1"
            android:text="This is a generic message"
            android:layout_gravity="center_horizontal" />

        <Button
            android:layout_width="48dp"
            android:id="@+id/button22"
            android:layout_height="match_parent"
            android:scaleType="centerCrop"
            android:background="@drawable/play" />


    </LinearLayout>


</LinearLayout>

Upvotes: 0

Views: 79

Answers (1)

anoo_radha
anoo_radha

Reputation: 822

You can use listview to get your needed layout. There is no need of adding a separate scrollview as listview itself is scrollable.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/backgnd"
android:layout_marginRight="24dp"
android:layout_marginLeft="24dp">
       <ListView
        android:id="@+id/list"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" />
</LinearLayout>

and then define another layout for each item in the list view, for example item.xml as

<LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal"
        android:baselineAligned="false">
        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_margin="@dimen/text_margin"
            android:layout_weight="1"
            android:text="This is a generic message"
            android:layout_gravity="center_horizontal" />
        <Button
            android:layout_width="48dp"
            android:id="@+id/button22"
            android:layout_height="match_parent"
            android:scaleType="centerCrop"
            android:background="@drawable/play" />
</LinearLayout>

Use an adapter to display content in the listview. In the getView() function of the adapter, you can inflate the view with the item.xml layout. For example,

@Override
public View getView(int position, View convertView, ViewGroup parent) {
  View rowView = mInflater.inflate(R.layout.item, parent, false);
  return rowView;
}

This is to give you an idea. Please alter it to your project.

Upvotes: 1

Related Questions