Reputation: 473
I am making an app in which i want to put different layouts for landscape as well as portrait mode of the view.I have made a separate folder layout-land for that purpose but when i move the device to landscape mode,its not working.Please tell me the solution.
This is the activity:
package com.example.fragmenttest;
import android.app.Activity;
import android.os.Bundle;
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
This is the xml file for this activity:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:id="@+id/rl"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="@string/hello_world"
/>
<com.google.ads.AdView
android:id="@+id/ad"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
ads:adSize="SMART_BANNER"
ads:adUnitId="a1501e5633125fb"
ads:loadAdOnCreate="true"
ads:testDevices="TEST_EMULATOR, 123456789ABCDEF" />
</RelativeLayout>
This is the xml of the layout in layout-land folder:
<?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="match_parent"
android:orientation="vertical"
android:background="@drawable/ic_action_search"
>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="This is fragment 2 "
/>
</LinearLayout>
Upvotes: 4
Views: 2528
Reputation: 56925
Change that landscape file name to activity_main
. Both the file name must be same .
Upvotes: 3