随着手机不同尺寸的推出,加上平板市场的火热,很多软件开始做左侧导航,右侧详情,这样可以方便我们更加直观的看到详情。
例如这样:
下面就用简洁明了的代码来说怎样实现的吧!
直接上步骤
1.在AndroidManifest里面先把Activity设置成横屏显示
加粗这块放进去即可,当然不设置也没事哈
这句话:
android:screenOrientation=”landscape”
<activity android:name=".MainActivity"
android:screenOrientation="landscape"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
2.再去写布局啦
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.holly.mytest4">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity"
android:screenOrientation="landscape"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
再写左侧的fragment布局,取名:left_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white"
android:orientation=