Вы должны прочитать это
Создайте две папки макета, как показано ...
В обеих папках ваш файл макетаимя должно быть таким же.
В папке layout-port
ваш файл макета должен выглядеть следующим образом ...
android:layout_toRightOf="@id/surface_camera"
заменен на ...
android:layout_Below="@id/surface_camera"
какследует ...
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:layout_width="fill_parent"
android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android"
>
<SurfaceView android:layout_width="450dip"
android:layout_height="fill_parent" android:id="@+id/surface_camera" />
<RelativeLayout android:layout_width="fill_parent"
android:layout_toBelow="@id/surface_camera"
android:layout_height="fill_parent"
>
<Button android:layout_width="680dip"
android:layout_height="680dip"
android:id="@+id/btnPhoto"
android:layout_alignParentBottom="true"
android:text="Take Photo"
android:layout_gravity="bottom|right" />
</RelativeLayout>
</RelativeLayout>
Даже это будет считаться плохой практикой, но вы также можете справиться с этим вручную, попробуйте это ..
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.main);
int orientation = getResources().getConfiguration().orientation;
if(orientation == Configuration.ORIENTATION_PORTRAIT) {
setContentView(R.layout.main1);
}
else {
setContentView(R.layout.main2);
}
}
Также Если вы делаете это не нужночтобы создать две папки макета, но для этого нужны два файла макета main1 и main2 в одной папке
Еще один вариант ...
В манифесте ...
<activity android:name=".ActivityName" android:configChanges="keyboardHidden|orientation">
+
В вашей деятельности ...
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
int orientation = newConfig.orientation;
if(orientation == Configuration.ORIENTATION_PORTRAIT) {
setContentView(R.layout.main2);
}
else {
setContentView(R.layout.main);
}
}