Scrollview having HorizontalScrollview lags when scrolling - android

I am trying to use horizontal scrollview inside a scroll view. My parent scroll isn't scrolling smoothly. Although my child scroll is scrolling smoothly, I want to achieve smooth scrolling of parent scroll. I have tried every method, I have in my mind setting HardwareAccelerated to false worked but it removed elevation from my views.
Main Activity
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
android:background="#ECEFF1"
android:clipToPadding="false">
<RelativeLayout
android:layout_width="250dp"
android:layout_height="90dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginLeft="75dp"
android:layout_marginTop="100dp"
android:background="#drawable/round_corners"
android:clipToPadding="false"
android:elevation="5dp"
android:translationZ="5dp"
tools:layout_editor_absoluteX="42dp"
tools:layout_editor_absoluteY="121dp">
<ImageView
android:id="#+id/enquiry"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_alignParentEnd="true"
android:layout_alignTop="#+id/visa"
android:layout_marginEnd="35dp"
app:srcCompat="#drawable/phone" />
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignTop="#+id/textView2"
android:layout_marginEnd="20dp"
android:text="Enquiry"
android:textColor="#color/navigationBarColor"
android:textSize="15sp" />
<ImageView
android:id="#+id/visa"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_alignTop="#+id/holidays"
android:layout_centerHorizontal="true"
app:srcCompat="#drawable/globe" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/textView3"
android:layout_centerHorizontal="true"
android:text="Visa"
android:textColor="#android:color/background_dark"
android:textSize="15sp" />
<ImageView
android:id="#+id/holidays"
android:layout_width="25dp"
android:layout_height="32dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginStart="35dp"
android:layout_marginTop="18dp"
app:srcCompat="#drawable/plane" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
android:layout_marginBottom="14dp"
android:layout_marginStart="20dp"
android:text="Holidays"
android:textColor="#android:color/background_dark" />
</RelativeLayout>
<include
android:id="#+id/toolbar"
layout="#layout/app_bar" />
<Button
android:id="#+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="false"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:background="#color/colorPrimary"
android:fontFamily="serif"
android:text="Call"
android:textColor="#color/textColorPrimary"
android:textSize="20sp" />
<ScrollView
android:id="#+id/parent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="200dp"
android:scrollbars="none">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="30dp"
android:orientation="vertical">
<TextView
android:id="#+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
android:layout_marginBottom="0dp"
android:layout_marginLeft="25dp"
android:layout_marginTop="50dp"
android:text="Pilgrimage"
android:textColor="#android:color/background_dark"
android:textSize="25sp"
android:textStyle="bold" />
<android.support.v7.widget.CardView
android:id="#+id/pilg"
class="com.example.admin.myapplication.Pilgrimage"
android:layout_width="320dp"
android:layout_height="240dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginLeft="25dp"
android:layout_marginTop="20dp"
android:background="#drawable/round_corners"
android:elevation="5dp">
<ImageView
android:layout_width="match_parent"
android:layout_height="150dp"
android:background="#drawable/hu" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="100dp"
android:layout_marginTop="155dp"
android:fontFamily="serif"
android:text="Hajj And Umrah"
android:textColor="#color/navigationBarColor"
android:textSize="15sp"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="190dp"
android:text="Ramzan Umrah"
android:textColor="#color/colorPrimaryDark"
android:textSize="12sp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="210dp"
android:layout_marginTop="190dp"
android:text="29 Days/30 Nights"
android:textColor="#color/colorPrimaryDark"
android:textSize="12sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="205dp"
android:text="Starts From Rs.65,000/-"
android:textColor="#color/colorPrimaryDark"
android:textSize="12sp" />
</android.support.v7.widget.CardView>
<TextView
android:id="#+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="25dp"
android:layout_marginTop="25dp"
android:text="Holiday Packages"
android:textColor="#color/navigationBarColor"
android:textSize="25sp"
android:textStyle="bold" />
<HorizontalScrollView
android:id="#+id/child"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="none">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal">
<RelativeLayout
android:id="#+id/international"
class="com.example.admin.myapplication.International"
android:layout_width="200dp"
android:layout_height="225dp"
android:layout_marginBottom="30dp"
android:layout_marginLeft="25dp"
android:layout_marginTop="20dp"
android:background="#mipmap/ll"
android:elevation="5dp"
android:padding="-25dp">
<TextView
android:id="#+id/textView11"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="11dp"
android:fontFamily="serif"
android:text="International"
android:textColor="#color/textColorPrimary"
android:textSize="20sp" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/dom1"
android:layout_width="200dp"
android:layout_height="225dp"
android:layout_marginBottom="30dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="25dp"
android:layout_marginTop="20dp"
android:background="#mipmap/rajasthan"
android:elevation="5dp">
<TextView
android:id="#+id/textView12"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="12dp"
android:fontFamily="serif"
android:text="Domestic"
android:textColor="#color/textColorPrimary"
android:textSize="20sp" />
</RelativeLayout>
</LinearLayout>
</HorizontalScrollView>
<TextView
android:id="#+id/textView10"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="30dp"
android:layout_marginLeft="25dp"
android:layout_marginTop="25dp"
android:text="Social"
android:textColor="#color/navigationBarColor"
android:textSize="25sp" />
<LinearLayout
android:layout_width="335dp"
android:layout_height="50dp"
android:layout_marginBottom="100dp"
android:layout_marginLeft="25dp"
android:orientation="horizontal">
</LinearLayout>
</LinearLayout>
</ScrollView>
<TextView
android:id="#+id/textView13"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="14dp"
android:fontFamily="serif"
android:text="Al Shariq Enterprises"
android:textColor="#color/textColorPrimary"
android:textSize="20sp"
android:textStyle="bold" />
</RelativeLayout>

Try this NestedScrollView like this :-
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="200dp">
<android.support.v4.widget.NestedScrollView
android:id="#+id/parent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="30dp"
android:orientation="vertical">
<TextView
android:id="#+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
android:layout_marginBottom="0dp"
android:layout_marginLeft="25dp"
android:layout_marginTop="50dp"
android:text="Pilgrimage"
android:textColor="#android:color/background_dark"
android:textSize="25sp"
android:textStyle="bold" />
<android.support.v7.widget.CardView
android:id="#+id/pilg"
class="com.example.admin.myapplication.Pilgrimage"
android:layout_width="320dp"
android:layout_height="240dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginLeft="25dp"
android:layout_marginTop="20dp"
android:background="#drawable/round_corners"
android:elevation="5dp">
<ImageView
android:layout_width="match_parent"
android:layout_height="150dp"
android:background="#drawable/hu" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="100dp"
android:layout_marginTop="155dp"
android:fontFamily="serif"
android:text="Hajj And Umrah"
android:textColor="#color/navigationBarColor"
android:textSize="15sp"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="190dp"
android:text="Ramzan Umrah"
android:textColor="#color/colorPrimaryDark"
android:textSize="12sp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="210dp"
android:layout_marginTop="190dp"
android:text="29 Days/30 Nights"
android:textColor="#color/colorPrimaryDark"
android:textSize="12sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="205dp"
android:text="Starts From Rs.65,000/-"
android:textColor="#color/colorPrimaryDark"
android:textSize="12sp" />
</android.support.v7.widget.CardView>
<TextView
android:id="#+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="25dp"
android:layout_marginTop="25dp"
android:text="Holiday Packages"
android:textColor="#color/navigationBarColor"
android:textSize="25sp"
android:textStyle="bold" />
<HorizontalScrollView
android:id="#+id/child"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="none">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal">
<RelativeLayout
android:id="#+id/international"
class="com.example.admin.myapplication.International"
android:layout_width="200dp"
android:layout_height="225dp"
android:layout_marginBottom="30dp"
android:layout_marginLeft="25dp"
android:layout_marginTop="20dp"
android:background="#mipmap/ll"
android:elevation="5dp"
android:padding="-25dp">
<TextView
android:id="#+id/textView11"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="11dp"
android:fontFamily="serif"
android:text="International"
android:textColor="#color/textColorPrimary"
android:textSize="20sp" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/dom1"
android:layout_width="200dp"
android:layout_height="225dp"
android:layout_marginBottom="30dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="25dp"
android:layout_marginTop="20dp"
android:background="#mipmap/rajasthan"
android:elevation="5dp">
<TextView
android:id="#+id/textView12"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="12dp"
android:fontFamily="serif"
android:text="Domestic"
android:textColor="#color/textColorPrimary"
android:textSize="20sp" />
</RelativeLayout>
</LinearLayout>
</HorizontalScrollView>
<TextView
android:id="#+id/textView10"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="30dp"
android:layout_marginLeft="25dp"
android:layout_marginTop="25dp"
android:text="Social"
android:textColor="#color/navigationBarColor"
android:textSize="25sp" />
<LinearLayout
android:layout_width="335dp"
android:layout_height="50dp"
android:layout_marginBottom="100dp"
android:layout_marginLeft="25dp"
android:orientation="horizontal">
</LinearLayout>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</LinearLayout>
For basic details you can check this link.

I think that this happens because both of your ScrollViews reacts to scrolling so it seems to you that it lags, but it actually don't, its just vertical ScrollView interrupting horizontal ScrollView.
It is not recommended using ScrollView inside another ScrollView. Instead use NestedScrollView as in this answer.

Related

Place ImageButton in the center of ImageView

How can I adjust the imageButton in the center of ImageView?
Below are the code I have tried:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/Theme.AppCompat"
android:background="#color/darkpurple"
android:minHeight="?attr/actionBarSize">
<Button
android:text="Save"
android:id="#+id/save"
android:background="#color/darkpurple"
android:layout_width="wrap_content"
android:layout_gravity="right"
android:textColor="#fff"
android:layout_height="wrap_content"
android:textSize="12sp" />
</android.support.v7.widget.Toolbar>
<ImageView
android:layout_height="200dp"
android:layout_width="200dp"
android:layout_marginTop="15dp"
android:background="#color/light_gray"
android:layout_below="#+id/toolbar"
android:layout_marginRight="25dp"
android:layout_alignParentRight="true"
android:id="#+id/imageView"
android:layout_gravity="center_horizontal" />
<Button
android:layout_width="65dp"
android:background="#drawable/camera"
android:layout_height="55dp"
android:layout_marginRight="5dp"
android:id="#+id/imageButtonOne"
android:paddingTop="100dp"
android:layout_marginTop="67dp"
android:layout_alignTop="#+id/imageView"
android:layout_alignRight="#+id/comments"
android:layout_alignEnd="#+id/comments" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/imageView"
android:layout_marginTop="10dp"
android:paddingLeft="20dp"
android:textColor="#color/red"
android:textStyle="bold"
android:id="#+id/Date"
android:textSize="15sp"
android:text="Date"/>
<EditText
android:layout_width="match_parent"
android:id="#+id/date"
android:layout_below="#+id/Date"
android:layout_height="wrap_content"
android:paddingLeft="20dp"
android:textSize="15sp"
android:hint="Date"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:paddingLeft="20dp"
android:textColor="#color/red"
android:textStyle="bold"
android:id="#+id/Amount"
android:textSize="15sp"
android:text="Amount"
android:layout_below="#+id/date" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/Amount"
android:paddingLeft="20dp"
android:id="#+id/amount"
android:inputType="numberDecimal"
android:textSize="15sp"
android:hint="Amount"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:paddingLeft="20dp"
android:textStyle="bold"
android:id="#+id/Comments"
android:textSize="15sp"
android:text="Comments"
android:layout_below="#+id/amount" />
<EditText
android:layout_width="290dp"
android:layout_height="120dp"
android:paddingBottom="80dp"
android:layout_marginTop="15dp"
android:layout_marginLeft="10dp"
android:paddingLeft="13dp"
android:id="#+id/comments"
android:textSize="15sp"
android:background="#drawable/roundedcorner_edittext"
android:hint="Comments"
android:layout_below="#+id/Comments"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
My ScreenShot
<FrameLayout android:layout_height="200dp"
android:layout_width="200dp"
android:layout_below="#+id/toolbar"
android:layout_marginRight="25dp"
android:layout_marginTop="15dp"
android:layout_alignParentRight="true">
<ImageView
android:layout_height="200dp"
android:layout_width="200dp"
android:background="#color/light_gray"
android:id="#+id/imageView"
android:layout_gravity="center_horizontal" />
<Button
android:layout_width="65dp"
android:background="#drawable/camera"
android:layout_height="55dp"
android:id="#+id/imageButtonOne"
android:layout_gravity = "center"
/>
</FrameLayout>
Check it.
Use code, it works for all screen size(Please replace image with yours):
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/Theme.AppCompat"
android:background="#color/colorPrimary"
android:minHeight="?attr/actionBarSize">
<Button
android:text="Save"
android:id="#+id/save"
android:background="#color/colorPrimary"
android:layout_width="wrap_content"
android:layout_gravity="right"
android:textColor="#fff"
android:layout_height="wrap_content"
android:textSize="12sp" />
</android.support.v7.widget.Toolbar>
<ImageView
android:layout_height="200dp"
android:layout_width="200dp"
android:layout_marginTop="15dp"
android:background="#color/colorPrimary"
android:layout_below="#+id/toolbar"
android:layout_marginRight="25dp"
android:layout_alignParentRight="true"
android:id="#+id/imageView"
android:layout_gravity="center_horizontal" />
<Button
android:layout_width="70dp"
android:background="#mipmap/ic_launcher"
android:layout_height="60dp"
android:layout_marginTop="70dp"
android:layout_marginRight="65dp"
android:id="#+id/imageButtonOne"
android:layout_alignTop="#+id/imageView"
android:layout_alignEnd="#+id/imageView" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/imageView"
android:layout_marginTop="10dp"
android:paddingLeft="20dp"
android:textColor="#color/colorPrimary"
android:textStyle="bold"
android:id="#+id/Date"
android:textSize="15sp"
android:text="Date"/>
<EditText
android:layout_width="match_parent"
android:id="#+id/date"
android:layout_below="#+id/Date"
android:layout_height="wrap_content"
android:paddingLeft="20dp"
android:textSize="15sp"
android:hint="Date"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:paddingLeft="20dp"
android:textColor="#color/colorPrimary"
android:textStyle="bold"
android:id="#+id/Amount"
android:textSize="15sp"
android:text="Amount"
android:layout_below="#+id/date" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/Amount"
android:paddingLeft="20dp"
android:id="#+id/amount"
android:inputType="numberDecimal"
android:textSize="15sp"
android:hint="Amount"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:paddingLeft="20dp"
android:textStyle="bold"
android:id="#+id/Comments"
android:textSize="15sp"
android:text="Comments"
android:layout_below="#+id/amount" />
<EditText
android:layout_width="290dp"
android:layout_height="120dp"
android:paddingBottom="80dp"
android:layout_marginTop="15dp"
android:layout_marginLeft="10dp"
android:paddingLeft="13dp"
android:id="#+id/comments"
android:textSize="15sp"
android:background="#mipmap/ic_launcher"
android:hint="Comments"
android:layout_below="#+id/Comments"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
The idea is simple, make changes according to this:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="250dp"
android:layout_height="250dp" >
<ImageView
android:id="#+id/base"
android:layout_height="250dp"
android:layout_width="250dp"
android:src="#drawable/home"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" />
<ImageButton
android:id="#+id/center"
android:layout_height="150dp"
android:layout_width="150dp"
android:src="#drawable/home"
android:layout_centerInParent="true"
android:layout_centerVertical="true" />
</RelativeLayout>
</RelativeLayout>
In order to move it to the top right corner, you can specify
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
to the Relative Layout with fixed widths, This places the Layout at the top right corner, then you can add margins to keep at a position where you require.
Hope it helps :)
Past this as it is
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/Theme.AppCompat"
android:background="#color/darkpurple"
android:minHeight="?attr/actionBarSize">
<Button
android:text="Save"
android:id="#+id/save"
android:background="#color/darkpurple"
android:layout_width="wrap_content"
android:layout_gravity="right"
android:textColor="#fff"
android:layout_height="wrap_content"
android:textSize="12sp" />
</android.support.v7.widget.Toolbar>
<RelativeLayout
android:id="#+id/rlImages"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_centerHorizontal="true"
android:layout_below="#+id/toolbar"
android:layout_marginRight="25dp"
android:layout_marginTop="15dp">
<ImageView
android:id="#+id/imageView"
android:layout_width="200dp"
android:layout_height="200dp"
android:background="#color/light_gray" />
<Button
android:id="#+id/imageButtonOne"
android:layout_width="65dp"
android:layout_height="55dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:background="#drawable/add_tag" />
</RelativeLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/rlImages"
android:layout_marginTop="10dp"
android:paddingLeft="20dp"
android:textColor="#color/red"
android:textStyle="bold"
android:id="#+id/Date"
android:textSize="15sp"
android:text="Date"/>
<EditText
android:layout_width="match_parent"
android:id="#+id/date"
android:layout_below="#+id/Date"
android:layout_height="wrap_content"
android:paddingLeft="20dp"
android:textSize="15sp"
android:hint="Date"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:paddingLeft="20dp"
android:textColor="#color/red"
android:textStyle="bold"
android:id="#+id/Amount"
android:textSize="15sp"
android:text="Amount"
android:layout_below="#+id/date" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/Amount"
android:paddingLeft="20dp"
android:id="#+id/amount"
android:inputType="numberDecimal"
android:textSize="15sp"
android:hint="Amount"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:paddingLeft="20dp"
android:textStyle="bold"
android:id="#+id/Comments"
android:textSize="15sp"
android:text="Comments"
android:layout_below="#+id/amount" />
<EditText
android:layout_width="290dp"
android:layout_height="120dp"
android:paddingBottom="80dp"
android:layout_marginTop="15dp"
android:layout_marginLeft="10dp"
android:paddingLeft="13dp"
android:id="#+id/comments"
android:textSize="15sp"
android:background="#drawable/roundedcorner_edittext"
android:hint="Comments"
android:layout_below="#+id/Comments"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
You need to use RelativeLayout with the use of
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_centerInParent="true"
You can use FrameLayout with that
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="center"
android:src="#drawable/img" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="20dip"
android:layout_gravity="center_horizontal|bottom"
android:padding="12dip"
android:background="#000000"
android:textColor="#ffffffff"
android:text="Button" />
</FrameLayout>

(Android studio) ScrollView won't scroll all the way to the bottom

im trying to put a scroll view inside a frame layout. My scroll view is not scrolling all the way to bottom. this is my xml code. It is working when i give a padding to scroll view. but i need a better answer. because giving a padding will make a white margin below my application. Thank you!
<FrameLayout 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="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
// this is your first layout to put the big image
// use src or backgroud image as per requirement
<LinearLayout
android:background="#drawable/bg"
android:layout_width="match_parent"
android:layout_height="180dp">
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/imageView"
android:background="#drawable/overly" />
</LinearLayout>
// this is your bottom layout
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#ffc9c9c9"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:id="#+id/relativeLayout"
android:layout_marginTop="8dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Anna Huffmunster"
android:id="#+id/textView2"
android:textStyle="bold"
android:textSize="20dp"
android:gravity="center"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:paddingTop="40dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Colombo Sri lanka"
android:id="#+id/txt_location"
android:textSize="15dp"
android:gravity="center"
android:textStyle="italic"
android:textColor="#696969"
android:paddingBottom="7dp"
android:paddingTop="5dp"
android:layout_below="#+id/textView2"
android:layout_centerHorizontal="true" />
</RelativeLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/scrollView"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="fill_parent"
android:gravity="center_horizontal"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:layout_below="#+id/relativeLayout"
android:layout_marginTop="12dp"
android:id="#+id/relativeLayout2">
<ImageButton
android:layout_width="50dp"
android:layout_height="50dp"
android:id="#+id/imageButton"
android:background="#drawable/call_button"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<ImageButton
android:layout_width="50dp"
android:layout_height="50dp"
android:id="#+id/imageButton2"
android:background="#drawable/chat_button"
android:layout_alignParentTop="true"
android:layout_toStartOf="#+id/imageButton"
android:layout_marginRight="30dp" />
<ImageButton
android:layout_width="50dp"
android:layout_height="50dp"
android:id="#+id/imageButton3"
android:background="#drawable/location_button"
android:layout_alignParentTop="true"
android:layout_toEndOf="#+id/imageButton"
android:layout_marginLeft="30dp" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/relativeLayout2"
android:layout_alignParentStart="true"
android:layout_marginTop="12dp"
android:id="#+id/relativeLayout3">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="“Live each day as if your life had just begun.” "
android:id="#+id/txt_status"
android:textColor="#ffd9162d"
android:textSize="12dp"
android:textStyle="italic"
android:gravity="center"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/relativeLayout3"
android:layout_alignParentStart="true">
<TextView
android:text="Birthday"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textView3"
android:textSize="12sp"
android:layout_marginStart="75dp"
android:layout_marginTop="23dp"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:textColor="#000" />
<TextView
android:text="19 MAR 1992"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textView4"
android:inputType="date"
android:layout_marginEnd="79dp"
android:textSize="12sp"
android:layout_alignBaseline="#+id/textView3"
android:layout_alignBottom="#+id/textView3"
android:layout_alignParentEnd="true" />
<TextView
android:text="Profession"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textView5"
android:layout_below="#+id/textView3"
android:layout_alignStart="#+id/textView3"
android:layout_marginTop="20dp"
android:textColor="#000"
android:textSize="12sp" />
<TextView
android:text="Software Engineer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textView6"
android:textSize="12sp"
android:maxWidth="20dp"
android:layout_alignTop="#+id/textView5"
android:layout_alignStart="#+id/textView4"
android:layout_alignEnd="#+id/textView4" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true">
<TextView
android:text="dgsdfsdfdfsdfsdfvv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textView8"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true" />
<TextView
android:text="dgsdfsdfdfsdfsdfvv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textView11"
android:layout_below="#+id/textView8"
android:layout_alignParentStart="true" />
<TextView
android:text="dgsdfsdfdfsdfsdfvv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textView9"
android:layout_below="#+id/textView11"
android:layout_alignParentStart="true" />
<TextView
android:text="dgsdfsdfdfsdfsdfvv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textView10"
android:layout_below="#+id/textView9"
android:layout_alignParentStart="true" />
</RelativeLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
// This is the imageview which overlay the first LinearLayout
<ImageView
android:layout_width="122dp"
android:layout_height="122dp"
android:src="#drawable/circle_profile_pic"
android:adjustViewBounds="true"
android:layout_gravity="center_horizontal"
android:layout_marginTop="100dp"
android:background="#drawable/stroke"/>

How to add a layout multiple times in parent layout onClick of another layout?

I have a parent layout in which I want to add a child layout onClick of another layout. The layout I want to add it's visibility is gone right now. After clicking on NextDestination layout it shows the another layout which is LinearAddedDestination. I want to add this layout when the user clicks on NextDestination layout till 14 times after 14 times the NextDestination layout should not be visible.
How can I achieve this??
GoBoxActivity Layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_weight="1.00"
android:background="#android:color/white"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="DESTINATION"
android:id="#+id/textView14"
android:layout_marginStart="20dp"
android:layout_marginTop="20dp" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="40dp"
android:orientation="horizontal"
android:background="#drawable/shape"
android:gravity="right"
android:layout_gravity="center|right"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:layout_marginLeft="100dp"
android:id="#+id/LinearRemove"
android:visibility="gone">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/ic_clear_black_18dp"
android:layout_marginLeft="05dp"
android:layout_marginTop="05dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="REMOVE"
android:id="#+id/textView47"
android:layout_gravity="center"
android:layout_marginLeft="05dp"
android:textSize="14sp"
android:layout_marginRight="15dp" />
</LinearLayout>
</LinearLayout>
<ImageView
android:layout_width="match_parent"
android:layout_height="08dp"
android:id="#+id/imageView14"
android:background="#drawable/line2"/>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:layout_width="25dp"
android:layout_height="25dp"
android:id="#+id/imageView10"
android:layout_marginStart="20dp"
android:background="#drawable/ic_place_black_48dp"
android:layout_marginTop="05dp"
android:layout_gravity="center" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/Text_to"
android:drawableEnd="#drawable/ic_chevron_right_black_24dp"
android:layout_marginEnd="10dp"
android:text="#string/Loc"
android:layout_gravity="center"
android:layout_marginTop="05dp"
android:textAppearance="#android:style/TextAppearance.Medium"
android:cursorVisible="false"/>
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Street/Building/Place"
android:layout_marginStart="48dp"/>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:layout_width="25dp"
android:layout_height="25dp"
android:id="#+id/imageView17"
android:layout_marginStart="20dp"
android:background="#drawable/ic_description_black_48dp"
android:layout_marginTop="10dp" />
<EditText
android:layout_width="match_parent"
android:layout_height="45dp"
android:id="#+id/editText_to_details"
android:layout_marginEnd="10dp"
android:hint="#string/LocationDetails"/>
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:id="#+id/textViewHouseDetailsTo"
android:layout_marginStart="48dp"
android:hint="#string/HouseDetails" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:id="#+id/LinearLayoutAdditionalContactTo">
<ImageView
android:layout_width="25dp"
android:layout_height="25dp"
android:id="#+id/imageView18"
android:layout_marginStart="20dp"
android:background="#drawable/ic_person_black_48dp"
android:layout_marginTop="05dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/contactDetailsTo"
android:layout_marginEnd="10dp"
android:text="#string/additionalContact"
android:textAppearance="?android:attr/textAppearanceMedium"
android:drawableEnd="#drawable/ic_expand_more_black_24dp"
android:layout_marginTop="08dp"
android:layout_marginStart="05dp" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="60dp"
android:layout_marginEnd="50dp"
android:layout_gravity="center"
android:visibility="gone"
android:id="#+id/LinearLayoutTo"
android:layout_marginTop="20dp">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/editTex"
android:layout_weight="1"
android:hint="Name"
android:layout_gravity="center"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/editTe"
android:layout_weight="1"
android:hint="Phone"
android:layout_gravity="center"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="#string/or"
android:id="#+id/textViewInputIfSender"
android:layout_gravity="center"
android:layout_marginTop="20dp" />
<LinearLayout
android:layout_width="220dp"
android:layout_height="40dp"
android:background="#drawable/shape"
android:layout_gravity="center_horizontal">
<ImageButton
android:layout_width="20dp"
android:layout_height="20dp"
android:id="#+id/imageButton1"
android:background="#drawable/phone2"
android:layout_gravity="center"
android:layout_marginStart="30dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="#string/addFromContacts"
android:id="#+id/textView35"
android:layout_gravity="center"
android:layout_marginStart="20dp" />
</LinearLayout>
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:id="#+id/textViewInputReceiver"
android:layout_marginLeft="48dp"
android:hint="#string/contact1"
android:layout_marginTop="10dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:focusable="true"
android:focusableInTouchMode="true">
<ImageView
android:layout_width="25dp"
android:layout_height="25dp"
android:id="#+id/imageView12"
android:layout_marginStart="20dp"
android:background="#drawable/ic_description_black_48dp"
android:layout_marginTop="10dp" />
<EditText
android:layout_width="match_parent"
android:layout_height="45dp"
android:id="#+id/editText_from_details"
android:layout_marginEnd="10dp"
android:hint="Instruction"
android:layout_gravity="center"
android:layout_marginLeft="10dp" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_weight="1.00"
android:background="#android:color/white"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:id="#+id/LinearAddedDestination"
android:visibility="gone">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="DESTINATION"
android:id="#+id/textView14"
android:layout_marginStart="20dp"
android:layout_marginTop="20dp" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="40dp"
android:orientation="horizontal"
android:background="#drawable/shape"
android:gravity="right"
android:layout_gravity="center|right"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:layout_marginLeft="80dp"
android:id="#+id/LinearRemove">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/ic_clear_black_18dp"
android:layout_marginLeft="05dp"
android:layout_marginTop="05dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="REMOVE"
android:id="#+id/textView47"
android:layout_gravity="center"
android:layout_marginLeft="05dp"
android:textSize="14sp"
android:layout_marginRight="15dp" />
</LinearLayout>
</LinearLayout>
<ImageView
android:layout_width="match_parent"
android:layout_height="08dp"
android:id="#+id/imageView14"
android:background="#drawable/line2"/>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:layout_width="25dp"
android:layout_height="25dp"
android:id="#+id/imageView10"
android:layout_marginStart="20dp"
android:background="#drawable/ic_place_black_48dp"
android:layout_marginTop="05dp"
android:layout_gravity="center" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/Text_to"
android:drawableEnd="#drawable/ic_chevron_right_black_24dp"
android:layout_marginEnd="10dp"
android:text="#string/Loc"
android:layout_gravity="center"
android:layout_marginTop="05dp"
android:textAppearance="#android:style/TextAppearance.Medium"
android:cursorVisible="false"/>
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Street/Building/Place"
android:layout_marginStart="48dp"/>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:layout_width="25dp"
android:layout_height="25dp"
android:id="#+id/imageView17"
android:layout_marginStart="20dp"
android:background="#drawable/ic_description_black_48dp"
android:layout_marginTop="10dp" />
<EditText
android:layout_width="match_parent"
android:layout_height="45dp"
android:id="#+id/editText_to_details"
android:layout_marginEnd="10dp"
android:hint="#string/LocationDetails"/>
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:id="#+id/textViewHouseDetailsTo"
android:layout_marginStart="48dp"
android:hint="#string/HouseDetails" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:id="#+id/LinearLayoutAdditionalContactTo">
<ImageView
android:layout_width="25dp"
android:layout_height="25dp"
android:id="#+id/imageView18"
android:layout_marginStart="20dp"
android:background="#drawable/ic_person_black_48dp"
android:layout_marginTop="05dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/contactDetailsTo"
android:layout_marginEnd="10dp"
android:text="#string/additionalContact"
android:textAppearance="?android:attr/textAppearanceMedium"
android:drawableEnd="#drawable/ic_expand_more_black_24dp"
android:layout_marginTop="08dp"
android:layout_marginStart="05dp" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="60dp"
android:layout_marginEnd="50dp"
android:layout_gravity="center"
android:visibility="gone"
android:id="#+id/LinearLayoutTo"
android:layout_marginTop="20dp">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/editTex"
android:layout_weight="1"
android:hint="Name"
android:layout_gravity="center"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/editTe"
android:layout_weight="1"
android:hint="Phone"
android:layout_gravity="center"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="#string/or"
android:id="#+id/textViewInputIfSender"
android:layout_gravity="center"
android:layout_marginTop="20dp" />
<LinearLayout
android:layout_width="220dp"
android:layout_height="40dp"
android:background="#drawable/shape"
android:layout_gravity="center_horizontal">
<ImageButton
android:layout_width="20dp"
android:layout_height="20dp"
android:id="#+id/imageButton1"
android:background="#drawable/phone2"
android:layout_gravity="center"
android:layout_marginStart="30dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="#string/addFromContacts"
android:id="#+id/textView35"
android:layout_gravity="center"
android:layout_marginStart="20dp" />
</LinearLayout>
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:id="#+id/textViewInputReceiver"
android:layout_marginLeft="48dp"
android:hint="#string/contact1"
android:layout_marginTop="10dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:focusable="true"
android:focusableInTouchMode="true">
<ImageView
android:layout_width="25dp"
android:layout_height="25dp"
android:id="#+id/imageView12"
android:layout_marginStart="20dp"
android:background="#drawable/ic_description_black_48dp"
android:layout_marginTop="10dp" />
<EditText
android:layout_width="match_parent"
android:layout_height="45dp"
android:id="#+id/editText_from_details"
android:layout_marginEnd="10dp"
android:hint="Instruction"
android:layout_gravity="center"
android:layout_marginLeft="10dp" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="40dp"
android:orientation="horizontal"
android:background="#drawable/shape"
android:layout_gravity="right"
android:layout_marginEnd="15dp"
android:layout_marginTop="15dp"
android:layout_marginBottom="15dp"
android:id="#+id/LinearNextDestination">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/ic_add_black_18dp"
android:layout_marginLeft="05dp"
android:layout_marginTop="05dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="NEXT DESTINATION"
android:id="#+id/textView47"
android:layout_gravity="center"
android:layout_marginLeft="05dp"
android:textSize="14sp"
android:layout_marginRight="15dp" />
</LinearLayout>
</LinearLayout>
You are having many layout as the child layout for the main layout. But the better way to achieve your goal is to add fragment.
Using the fragment you can easily change the layouts view. Look at these links. Adding fragment will solve your problem.
http://developer.android.com/training/basics/fragments/creating.html
http://examples.javacodegeeks.com/android/core/app/fragment/android-fragments-example/
http://www.vogella.com/tutorials/AndroidFragments/article.html
http://www.learn2crack.com/2014/05/android-working-with-fragments.html
Using the fragment you can divide the space in the layout and add multiple fragments inside that.

how do i use both scroll view and RecyclerView in one xml layout android?

In my application i am using recycler view and scrollview in one layout. it is not working when i am using both these views. If i remove scroll view only the recycler view is working. Plese any one help me hoe to fix this issue.
my code:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/r1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/background"
>
<ScrollView
android:id="#+id/sc"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#1e356a">
<TextView
android:id="#+id/placce_head"
android:layout_width="wrap_content"
android:layout_height="25dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:text="Hyderabad to banglore"
android:textColor="#ffffff"
android:textSize="20dp" />
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#78869c"
android:weightSum="2"
android:orientation="horizontal">
<TextView
android:id="#+id/seats"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:text="Selected Seats"
android:textColor="#ffffff"
android:textSize="16dp" />
<TextView
android:id="#+id/totalamount"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:text="Total Amount"
android:textColor="#ffffff"
android:textSize="16dp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#78869c"
android:weightSum="2"
android:orientation="horizontal">
<TextView
android:id="#+id/seat_num"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_marginLeft="20dp"
android:textColor="#ffffff"
android:textSize="16dp" />
<TextView
android:id="#+id/total_amount"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginLeft="10dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:textColor="#ffffff"
android:textSize="16dp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<EditText
android:id="#+id/boardingpoint_edttxt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusableInTouchMode="false"
android:layout_marginLeft="30dp"
android:layout_marginTop="22dp"
android:background="#null"
android:hint=" Select Boarding Point"
android:textColorHint="#1e365a"
android:textSize="15dp" />
<View
android:layout_width="fill_parent"
android:layout_height="0.8dp"
android:layout_marginLeft="25dp"
android:layout_marginRight="25dp"
android:layout_marginTop="7dp"
android:background="#1e365a" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#78869c"
android:layout_marginTop="20dp">
<TextView
android:id="#+id/contact_details"
android:layout_width="wrap_content"
android:layout_height="25dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:text="Contact Details"
android:textColor="#ffffff"
android:textSize="20dp" />
</RelativeLayout>
<EditText
android:id="#+id/contactname_edt_txt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_marginTop="22dp"
android:background="#null"
android:hint="Contact Name"
android:textColorHint="#1e365a"
android:textSize="15dp" />
<View
android:layout_width="fill_parent"
android:layout_height="0.8dp"
android:layout_marginLeft="25dp"
android:layout_marginRight="25dp"
android:layout_marginTop="7dp"
android:background="#1e365a" />
<EditText
android:id="#+id/email_edt_txt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_marginTop="22dp"
android:background="#null"
android:hint="Email Address"
android:textColorHint="#1e365a"
android:textSize="15dp" />
<View
android:layout_width="fill_parent"
android:layout_height="0.8dp"
android:layout_marginLeft="25dp"
android:layout_marginRight="25dp"
android:layout_marginTop="7dp"
android:background="#1e365a" />
<EditText
android:id="#+id/contactnum_edt_txt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_marginTop="22dp"
android:background="#null"
android:hint="Contact Number"
android:textColorHint="#1e365a"
android:textSize="15dp" />
<View
android:layout_width="fill_parent"
android:layout_height="0.8dp"
android:layout_marginLeft="25dp"
android:layout_marginRight="25dp"
android:layout_marginTop="7dp"
android:background="#1e365a" />
<EditText
android:id="#+id/emergency_edt_txt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_marginTop="22dp"
android:background="#null"
android:hint="Emergency Contact Number"
android:textColorHint="#1e365a"
android:textSize="15dp" />
<View
android:layout_width="fill_parent"
android:layout_height="0.8dp"
android:layout_marginLeft="25dp"
android:layout_marginRight="25dp"
android:layout_marginTop="7dp"
android:background="#1e365a" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#78869c"
android:layout_marginTop="20dp">
<TextView
android:id="#+id/passenger_details"
android:layout_width="wrap_content"
android:layout_height="25dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:text="Passenger Details"
android:textColor="#ffffff"
android:textSize="20dp" />
</RelativeLayout>
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/view"
android:layout_below="#+id/sc"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<LinearLayout
android:id="#+id/coupon_lay"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="8dp"
android:layout_marginTop="12dp"
android:gravity="center_vertical"
android:orientation="horizontal"
android:weightSum="100" >
<EditText
android:id="#+id/entercouponcode_edt"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_weight="50"
android:hint="Enter coupn code"
android:inputType="text" >
<requestFocus />
</EditText>
<Button
android:id="#+id/bt_apply"
style="#style/payment_button_style"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_marginLeft="-5dp"
android:layout_weight="40"
android:gravity="center"
android:text="Apply" />
</LinearLayout>
<Button
android:id="#+id/pay_btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="28dp"
android:layout_marginRight="30dp"
android:layout_marginTop="20dp"
android:background="#F93249"
android:duplicateParentState="true"
android:gravity="center"
android:paddingBottom="8dp"
android:paddingTop="8dp"
android:text="Proceed to Pay"
android:textColor="#ffffff"
android:textSize="20dp"/>
</LinearLayout>
</ScrollView>
</RelativeLayout>
you must know that ,your scrollview property is set as MatchParent ,which means it will fill the content view, so i suggest to set Height a real value such as 100dp, and it will work
You need to dynamically change the height of the recyclerview, depending on how many items you have.
int recyclerheight = height_per_item * adapterData.size();
recyclerView.getLayoutParams().height = recyclerheight;
The scroll view blocks the recyclerview from changing its height set in the xml, that's why you need to do it programically.

ImageViews being cut off and resized

I have a three section relative layout for a login page.
The first section at the top of the page is 1 Imageview and 2 Textviews.
The second section is 6 RelativeLayouts containing 1 ImageView to the left and 1 TextView to the right.
The third section is a Button
The first four icons are ok on any device. The 5th and 6th are both getting resized or not showing up.
I would like to see all 6 but if 1 can't fit dont add it. How can I do this in a proper way.
Thanks - P.S Code is below
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/newd_login_overlay"
android:orientation="vertical" >
<LinearLayout android:id="#+id/linLoginText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:orientation="vertical" >
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="#drawable/login_logo_white" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="#string/newd_login_text_one"
android:textColor="#android:color/white"
android:textSize="24sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="#string/newd_login_text_two"
android:textColor="#android:color/white"
android:textSize="18sp" />
</LinearLayout>
<LinearLayout
android:id="#+id/linLoginFeature"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/btnLoginCreate"
android:layout_below="#+id/linLoginText"
android:layout_marginLeft="5dp"
android:layout_marginStart="5dp"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp">
<ImageView android:id="#+id/imgLoginSecurity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:src="#drawable/newd_security"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:layout_toRightOf="#+id/imgLoginSecurity"
android:layout_toEndOf="#+id/imgLoginSecurity"
android:layout_centerVertical="true"
android:text="#string/newd_login_security"
android:textColor="#android:color/white"
android:textSize="18sp" />
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp">
<ImageView android:id="#+id/imgLoginAntivirus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:src="#drawable/newd_antivirus"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:layout_toRightOf="#+id/imgLoginAntivirus"
android:layout_toEndOf="#+id/imgLoginAntivirus"
android:layout_centerVertical="true"
android:text="#string/newd_login_antivirus"
android:textColor="#android:color/white"
android:textSize="18sp" />
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp">
<ImageView android:id="#+id/imgLoginTracker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:src="#drawable/newd_phone_tracker"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:layout_toRightOf="#+id/imgLoginTracker"
android:layout_toEndOf="#+id/imgLoginTracker"
android:layout_centerVertical="true"
android:text="#string/newd_login_booster"
android:textColor="#android:color/white"
android:textSize="18sp" />
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp">
<ImageView android:id="#+id/imgLoginBackup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:src="#drawable/newd_backup"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:layout_toRightOf="#+id/imgLoginBackup"
android:layout_toEndOf="#+id/imgLoginBackup"
android:layout_centerVertical="true"
android:text="#string/newd_login_backup"
android:textColor="#android:color/white"
android:textSize="18sp" />
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp">
<ImageView android:id="#+id/imgLoginPrivacy"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:src="#drawable/newd_privacy"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:layout_toRightOf="#+id/imgLoginPrivacy"
android:layout_toEndOf="#+id/imgLoginPrivacy"
android:layout_centerVertical="true"
android:text="#string/newd_login_privacy"
android:textColor="#android:color/white"
android:textSize="18sp" />
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp">
<ImageView android:id="#+id/imgLoginBooster"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:src="#drawable/newd_signal_booster"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:layout_toRightOf="#+id/imgLoginBooster"
android:layout_toEndOf="#+id/imgLoginBooster"
android:layout_centerVertical="true"
android:text="#string/newd_login_tracker"
android:textColor="#android:color/white"
android:textSize="18sp" />
</RelativeLayout>
</LinearLayout>
<Button
android:id="#+id/btnLoginCreate"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginRight="20dp"
android:layout_marginEnd="20dp"
android:layout_marginLeft="20dp"
android:layout_marginStart="20dp"
android:layout_alignParentBottom="true"
android:background="#drawable/newd_login_btn"
android:gravity="center"
android:text="#string/newd_login_btn_text"
android:textColor="#android:color/black" />
</RelativeLayout>
Use android:layout_weight
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/newd_login_overlay"
android:orientation="vertical" >
<LinearLayout android:id="#+id/linLoginText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:orientation="vertical" >
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="#drawable/login_logo_white" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="#string/newd_login_text_one"
android:textColor="#android:color/white"
android:textSize="24sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="#string/newd_login_text_two"
android:textColor="#android:color/white"
android:textSize="18sp" />
</LinearLayout>
<LinearLayout
android:id="#+id/linLoginFeature"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:weightSum="6"
android:layout_above="#+id/btnLoginCreate"
android:layout_below="#+id/linLoginText"
android:layout_marginLeft="5dp"
android:layout_marginStart="5dp"
android:orientation="vertical" >
<RelativeLayout
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp">
<ImageView android:id="#+id/imgLoginSecurity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:src="#drawable/newd_security"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:layout_toRightOf="#+id/imgLoginSecurity"
android:layout_toEndOf="#+id/imgLoginSecurity"
android:layout_centerVertical="true"
android:text="#string/newd_login_security"
android:textColor="#android:color/white"
android:textSize="18sp" />
</RelativeLayout>
<RelativeLayout
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp">
<ImageView android:id="#+id/imgLoginAntivirus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:src="#drawable/newd_antivirus"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:layout_toRightOf="#+id/imgLoginAntivirus"
android:layout_toEndOf="#+id/imgLoginAntivirus"
android:layout_centerVertical="true"
android:text="#string/newd_login_antivirus"
android:textColor="#android:color/white"
android:textSize="18sp" />
</RelativeLayout>
<RelativeLayout
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp">
<ImageView android:id="#+id/imgLoginTracker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:src="#drawable/newd_phone_tracker"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:layout_toRightOf="#+id/imgLoginTracker"
android:layout_toEndOf="#+id/imgLoginTracker"
android:layout_centerVertical="true"
android:text="#string/newd_login_booster"
android:textColor="#android:color/white"
android:textSize="18sp" />
</RelativeLayout>
<RelativeLayout
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp">
<ImageView android:id="#+id/imgLoginBackup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:src="#drawable/newd_backup"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:layout_toRightOf="#+id/imgLoginBackup"
android:layout_toEndOf="#+id/imgLoginBackup"
android:layout_centerVertical="true"
android:text="#string/newd_login_backup"
android:textColor="#android:color/white"
android:textSize="18sp" />
</RelativeLayout>
<RelativeLayout
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp">
<ImageView android:id="#+id/imgLoginPrivacy"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:src="#drawable/newd_privacy"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:layout_toRightOf="#+id/imgLoginPrivacy"
android:layout_toEndOf="#+id/imgLoginPrivacy"
android:layout_centerVertical="true"
android:text="#string/newd_login_privacy"
android:textColor="#android:color/white"
android:textSize="18sp" />
</RelativeLayout>
<RelativeLayout
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp">
<ImageView android:id="#+id/imgLoginBooster"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:src="#drawable/newd_signal_booster"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:layout_toRightOf="#+id/imgLoginBooster"
android:layout_toEndOf="#+id/imgLoginBooster"
android:layout_centerVertical="true"
android:text="#string/newd_login_tracker"
android:textColor="#android:color/white"
android:textSize="18sp" />
</RelativeLayout>
</LinearLayout>
<Button
android:id="#+id/btnLoginCreate"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginRight="20dp"
android:layout_marginEnd="20dp"
android:layout_marginLeft="20dp"
android:layout_marginStart="20dp"
android:layout_alignParentBottom="true"
android:background="#drawable/newd_login_btn"
android:gravity="center"
android:text="#string/newd_login_btn_text"
android:textColor="#android:color/black" />
</RelativeLayout>

Categories

Resources