KVM Virtual Machine Manager
The recommended amount of RAM for running Android Studio Ubuntu is 8GB. In Virtual Machine Manager the settings for virtual RAM are accessed by selecting the guest OS, then from the Virtual Machine Manager menu select Edit → Virtual Machine Details → click the blue ⓘ icon (Show virtual hardware details) to open a new window from which you select Memory and allocate at least 8GB memory to the guest OS.
Virtual Machine Manager configures the graphics and hardware-assisted virtualization settings automatically by default, but you may need to enable Intel VT-x or AMD-V hardware-assisted virtualization in UEFI/BIOS.
VT-x/AMD-V needs to be enabled to run the Android Emulator which is included with Android Studio in VirtualBox. If your computer's processor supports Intel VT-x or AMD-V hardware-assisted virtualization, there should also be settings to enable it in UEFI/BIOS. Make sure that the appropriate Intel VT-x or AMD-V settings are enabled in UEFI/BIOS. The following two checkboxes should be checked in VirtualBox Settings → System → Acceleration tab.
Enable Nested Paging
Android Studio is a very feature rich IDE, and you need to give it enough resources in order to use all of its great features. The recommended amount of RAM for running Android Studio Ubuntu is 8GB. As you get deeper into Android Studio you'll find out again and again what a resource hog it is. On a guest OS with only 4GB RAM whenever you run Android Studio's emulator, your guest OS will stop responding. Your guest OS will run smoothly if you add another 4GB RAM making it 8GB.
If you assign too much memory to the virtual machine, the machine might not start, so make sure there is enough memory left over for running the physical machine.
A guest OS in VirtualBox can be configured to use up to 256MB video memory. To increase the video memory to 256MB, open the terminal and type:
VBoxManage modifyvm "Name of VM" --vram 256
You can also configure the number of processors in VirtualBox Settings → System → Processor tab.