Speaking directly, it is not possible to separate layout files from apk and then try to access it using R.id.whatever
Extension files are intended for storing assets such as media, documents, and other similar static things that your application uses, and the contents of the extension package are stored on the shared device storage and are not associated with the apk file. In order to access the assets of the extension file, you must encode your application in order to read them from the shared storage repository.
Returning to the issue of saving layout files in an extension file. To do this, you will have to write your own parser layout with basic functions like LayoutInflator. You cannot use LayoutInflator to analyze any layout file that is not part of the apk or stored on any external storage. Therefore, the idea is to store the layout files in an extension file (which will be absent in apk, on the general device storage), analyze the file using its own analyzer, and add views to the main layout at runtime. Although you will not be able to access your views using R.id.whatever, you can always use the visual tree to access the views or, when analyzing the views, store the objects referenced to access them for later use.
Hope this gives you a starting point.
Vinod maurya
source share