0
的變化更換合適我想若用片段..但片段的配置變化重疊在活動佈局,幫助我,這怎麼解決這個改變片段的佈局... 這個類文件.........片段沒有在景觀和PORTTAINT
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" />
這是快照.... ....
如何做到這一點。你可以幫助我...這將是對我很有幫助...請。 – bhavdip
它會自動檢測和佈局將調整屏幕的大小...? – bhavdip
是的,Android會自動檢測設備的當前配置,然後選擇合適的佈局。 – brwngrldev