After lot of googling and community help I found the solution. Maybe helpful to someone looking the same as I did.
First you have to edit /etc/hosts file like below
127.0.0.1 localhost
127.0.1.1 myname-desktop
127.0.0.1 myname.projectname.dev
Secondly, /opt/lampp/etc/extra/httpd-vhosts.conf file has to be edited like
<VirtualHost *:80>
ServerAdmin webmaster@dummy-host2.example.com
DocumentRoot "/opt/lampp/htdocs/projectname"
ServerName myname.projectname.dev
ErrorLog "logs/myname.projectname.dev-error_log"
CustomLog "logs/myname.projectname.dev-access_log" common
</VirtualHost>
Finally in the xampp config file located in /opt/lampp/etc/httpd.conf, you have to uncomment the use of httpd-vhosts.conf file just by removing # in front of that.
# Virtual hosts
Include etc/extra/httpd-vhosts.conf
Now you are good to go. Make sure to restart the server once after making all the changes