I have certain widgets in LinearLayout
which is a child of ScrollView
. The problem is that the first widget in this case, the widget named "Title 1" is not visible it goes beyond the screen size as seen in this image,
I have tried the following but still it does not show my Title 1.
Added an attribute
android:fillViewport="true"
inScrollView
but it did not work.Added a
layout_gravity
(center_horizontal | center_vertical
) attribute but it didn't work.This question was specific to the OP's design Android ScrollView fillViewport not working and did not help much.
Note: I want the widget visible by not using any margin/padding attributes.
The code,
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
>
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:id="@+id/view_pager"
android:fillViewport="true"
android:focusableInTouchMode="true"
app:layout_constraintBottom_toTopOf="@+id/tabLayout"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingTop="10dp"
>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:gravity="center"
android:background="@color/green"
android:text="Title 1"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:gravity="center"
android:background="@color/green"
android:layout_marginTop="20dp"
android:text="Title 2"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:gravity="center"
android:background="@color/green"
android:layout_marginTop="20dp"
android:text="Title 3"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:gravity="center"
android:background="@color/green"
android:layout_marginTop="20dp"
android:text="Title 4"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:gravity="center"
android:background="@color/green"
android:layout_marginTop="20dp"
android:text="Title 5"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:gravity="center"
android:background="@color/green"
android:layout_marginTop="20dp"
android:text="Title 6"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:gravity="center"
android:background="@color/green"
android:layout_marginTop="20dp"
android:text="Title 7"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:gravity="center"
android:background="@color/green"
android:layout_marginTop="20dp"
android:text="Title 8"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:gravity="center"
android:background="@color/green"
android:layout_marginTop="20dp"
android:text="Title 9"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:gravity="center"
android:background="@color/green"
android:layout_marginTop="20dp"
android:text="Title 10"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:gravity="center"
android:background="@color/green"
android:layout_marginTop="20dp"
android:text="Title 11"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:gravity="center"
android:background="@color/green"
android:layout_marginTop="20dp"
android:text="Title 12"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:gravity="center"
android:background="@color/green"
android:layout_marginTop="20dp"
android:text="Title 13"
/>
</LinearLayout>
</ScrollView>
<android.support.design.widget.TabLayout
android:id="@+id/tabLayout"
style="@style/tabLayoutStyle"
app:layout_constraintBottom_toBottomOf="parent"
/>
</android.support.constraint.ConstraintLayout>
</LinearLayout>
EDIT 1
Changed height of LinearLayout(Inside scrollview) from match_parent
to wrap_content
but still didn't work.