조각은 풍경과 초상화의 변화에서 적절한 교체되지 않습니다.
-
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의 조각을 선언하고 활동에서도 프로그래머런 적으로 선언합니다.하나의 옵션을 선택해야합니다.
예를 들어 세로를위한 두 개의 다른 레이아웃 파일을 만들고 가로를 위해 하나씩 하나씩 만들고 조각을 선언하면 활동에서 특별한 일을 할 필요가 없습니다.
layout/my-layout
layout-land/my-layout
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.my_layout);
}
. 제휴하지 않습니다 StackOverflow