1
我有一個運行下面的代碼的動作條:動作條具有多個片段:片段佈局上移
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
ActionBar bar = getActionBar();
bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
bar.setDisplayShowTitleEnabled(false);
bar.addTab(bar.newTab()
.setText("Fragment_1")
.setTabListener(
new TabListener<ExampleFragment>(this, "Fragment_1", ExampleFragment.class)));
.
.
.
<Listener code that add the Fragment via FragmentTransaction>..
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.options_menu, menu);
MenuItem mSearchItem = menu.findItem(R.id.menu_fragments);
edit = (EditText) mSearchItem.getActionView().findViewById(R.id.edit);
return super.onCreateOptionsMenu(menu);
}
}
我的菜單options_menu.xml
是這樣的:
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/menu_fragments"
android:actionLayout="@layout/fragment"
android:showAsAction="always">
</item>
</menu>
我有如下的片段:
public class ExampleFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
ViewGroup view = (ViewGroup) inflater.inflate(R.layout.fragment, container, false);
return view;
}
}
而且我fragment.xml
是象下面這樣:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical" >
<FrameLayout
android:id="@+id/fragment_content"
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical" >
<ListView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1"
tools:listitem="@android:layout/simple_list_item_1" >
</ListView>
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/Button" />
</LinearLayout>
</LinearLayout>
現在,這個問題是,當我打電話的片段,其在fragment.xml
佈局被轉移了,當我選擇輸入一些東西。
如何解決這一問題?