Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
Win a copy of Programming with Types this week in the Angular and TypeScript forum
or The Design of Web APIs in the Web Services forum!
    Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Knute Snortum
  • Henry Wong
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Joe Ess
  • salvin francis

How do you re-use and extend an existing layout for use in another actvity?

Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Report post to moderator
Good Afternoon.

I am proficient in Java and now studying the basics of Android App Development.

I want to re-use the layout activity_main.xm  for a second activity to avoid the laborious work of having to re-create it in the layout editor.
In other words I want to sub-class the Activity ActivityMain but also "sub-class" its layout.

Any suggestion ?

I have searched and searched the web without success.

Mohammed Azeem
Ranch Hand
Posts: 75
  • Likes 1
  • Mark post as helpful
  • send pies
  • Report post to moderator
Solved. The answer is in the official android tutorials:

If you already have a layout and want to create an alternative version to optimize the layout for different screen sizes or orientations, follow these steps:
1. Open your original layout file and be sure you're viewing the design editor (click the Design tab at the bottom of the window).
2. Click Orientation for Preview   in the toolbar. In the dropdown list, either click a suggested variant such as Create Landscape Variant and you're done, or click Create Other and continue to the next step.
3. In the dialog that appears, you simply need to define the resource qualifiers for the directory name. You can type it in Directory name or select from the Available qualifiers list, one at a time, and click Add  .
4. Once you've added all your qualifiers, click OK.
When you have multiple variations of the same layout, you can easily switch between them from the list that appears when you click Layout Variants  .

It runs on an internal combustion engine. This ad does not:
Sauce Labs - World's Largest Continuous Testing Cloud for Websites and Mobile Apps
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!