フラグメントは風景や肖像画の変化に適したものを交換していません
-
21-12-2019 - |
質問
フラグメントを使用して構成変更がアクティビティレイアウトに重なっている場合は、フラグメントのレイアウトを変更したいので、これを解決する方法のために私を助けます... そしてこのクラスファイル.........
public class Self_funded_1 extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
Self_fragment ls_fragment = new Self_fragment();
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.self_funded_category);
Configuration config = getResources().getConfiguration();
FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager
.beginTransaction();
if (config.orientation == Configuration.ORIENTATION_LANDSCAPE) {
/**
* Landscape mode of the device
*/
Log.i("LM", "LM");
ls_fragment = new Self_fragment();
fragmentTransaction.replace(android.R.id.content, ls_fragment);
} else {
/**
* Portrait mode of the device
*/
Log.i("LM", "PM");
PM_self_funded pm_fragment = new PM_self_funded();
fragmentTransaction.replace(android.R.id.content, pm_fragment);
fragmentTransaction.remove(ls_fragment);
fragmentTransaction.hide(ls_fragment);
}
fragmentTransaction.commit();
}
.
アクティビティのXMLファイルです..
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<fragment
android:id="@+id/lm_fragment"
android:name="info.com.forms.Self_fragment"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" />
<fragment
android:id="@+id/pm_fragment"
android:name="info.com.forms.PM_self_funded"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" />
.
これはスナップショットです........
解決
XMLのフラグメントを宣言し、アクティビティでもプログラムでも宣言しています。1つのオプションを選択するだけです。
たとえば、縦横比で2つの異なるレイアウトファイルを作成し、横になる断片を宣言してから、アクティビティに特別なことをする必要はありません。
layout/my-layout
layout-land/my-layout
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.my_layout);
}
. 所属していません StackOverflow