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何かを入力することを選択したときにレイアウトが上に移動することです。

これを修正する方法は?

4

1 に答える 1

0

わかった。どうでも。問題が発生しました。

アクションバーのxmlファイル<requestFocus/>のEditTextウィジェットではばかげていました。@layout/main削除して動作するようになりました。

編集:申し訳ありませんが、問題は解決しませんでしたが、ついに解決策を見つけました。

含む、

android:windowSoftInputMode="adjustPan|adjustResize" のフラグメントをホストするアクティビティAndroidManifest.xml

キーパッド/テンキーを使用しても、レイアウトはシフトしません。

于 2012-12-17T02:42:33.827 に答える