我有一个运行以下代码的操作栏:
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
现在这个问题是,当我调用 Fragment 时,当我选择输入内容时,布局会向上移动。
如何解决这个问题?