我正在使用片段---
开发一个Android应用程序我的纵向模式布局:
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<FrameLayout
android:id="@+id/topics"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="3"
>
<fragment
android:id="@+id/cat_list_home"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.gitanjal.together.view.CategoryListFragment"
/>
</FrameLayout>
</LinearLayout>
横向模式的布局: -
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:baselineAligned="false"
android:orientation="horizontal"
android:weightSum="5"
>
<fragment
android:id="@+id/cat_list_home"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2"
class="com.gitanjal.together.view.CategoryListFragment" >
</fragment>
<FrameLayout
android:id="@+id/topics"
android:layout_width="0px"
android:layout_height="match_parent"
android:layout_weight="3"
>
</FrameLayout>
</LinearLayout>
现在我的应用程序的工作方式如下: -
在登录后的纵向模式下,会显示一个类别网格;有一个“创建类别”按钮,在点击时会加载一个片段“FormSuggestCategoryFragment”以显示一个表单,用户可以在其中输入新类别的名称和描述作为建议管理员创建此类别。
在登录后的横向模式中,有一个片段显示左侧的类别列表,点击“创建类别”按钮,建议类别的表单由右侧的片段显示。
现在我遇到的问题如下: -
在横向加载表单后,如果我旋转设备,则在横向模式下,两个片段(一个显示类别,另一个显示表单)重叠。
方法showSuggestCategoryForm:
private void showSuggestCategoryForm()
{
if(getResources().getConfiguration().orientation==Configuration.ORIENTATION_LANDSCAPE)
{
FormSuggestCategoryFragment formSuggestCategory=new FormSuggestCategoryFragment();
android.support.v4.app.FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.replace(R.id.topics, formSuggestCategory,"suggestForm");
ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
ft.addToBackStack(null);
ft.commit();
}
else
{
System.out.println("---------------------------------------In single pane mode : going to display create category form");
Intent intent=new Intent(getActivity(),FormSuggestCategoryActivity.class);
startActivity(intent);
}
}
onCreate:
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// TODO Auto-generated method stub
newRequest.requestGetCategories(contextParent,this); //Make the request
return inflater.inflate(R.layout.category_grids, null, false);
}
onActivityCreated方法:
public void onActivityCreated(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onActivityCreated(savedInstanceState);
//Get the create category button
Button btnCreateCategory=(Button) getActivity().findViewById(R.id.btnCreateCategory);
btnCreateCategory.setOnClickListener(new OnClickListener() {
//On clicking the Create category button display the fragment containing the Category create form : FormCreateCategoryFragment
public void onClick(View v) {
AppSettings.print_string("isAdmin----------"+SessionManager.isAdmin());
if(SessionManager.isAdmin())
{
//If the user is an Admin ; show the form to create a new category
AppSettings.print_string("As an admin displaying createCategoryForm");
showCreateCategoryForm();
}
else
{
//If the user is not an admin ; ask his suggestion for a new category
AppSettings.print_string("As not an admin displaying suggestCategoryForm");
showSuggestCategoryForm();
}
}
});
}