Is there a way to reuse a single activity layout-file (one orientation) for another activity with two orientations.
for example I have the MainActivity with one layout-file that just shows everything fullscreen:
activity_generic.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/fragmentContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:ignore="MergeRootFrame">
</FrameLayout>
MainActivity.java
setContentView(R.layout.activity_generic);
And then I have SettingsActivity which should show everything fullscreen in portrait-mode and everything splitscreen in landscape-mode.
activity_settings.xml
//use activity_generic.xml somehow
activity_settings.xml (land)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:baselineAligned="false">
<FrameLayout
android:id="@+id/content_left"
android:layout_width="0dp"
android:layout_weight="40"
android:layout_height="match_parent"/>
<FrameLayout
android:id="@+id/content_right"
android:layout_width="0dp"
android:layout_weight="60"
android:layout_height="match_parent"/>
</LinearLayout>
SettingsActivity.java
setContentView(R.layout.activity_settings);
Of course there is a way to fix this problem within code by checking the orientation and inflating another layout based on that, but it feels kind of hacky. I tried to use an include tag but it didn't work. Does anybody else know the solution to this problem?
Edit
I managed to edit the activity_settings.xml
so that it uses an include tag.
However it is a bit overkill because it uses almost as much code as the code from activity_generic.xml
.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<include layout="@layout/activity_generic"/>
</LinearLayout>
At this point i'm not sure if its even possible to use activity_generic.xml
instead of activity_settings.xml
(portrait).