簡體   English   中英

具有多個片段的操作欄:片段布局向上移動

[英]Actionbar with multiple fragments: Fragment Layout shifts up

我有一個運行以下代碼的操作欄:

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時,當我選擇鍵入某些內容時, fragment.xml的布局會上移。

如何解決這個問題?

好的。 沒關系。 我有問題。

這是操作欄的@layout/main xml文件中EditText小部件上的一個愚蠢的<requestFocus/> 刪除它,現在可以工作了。

編輯:對不起,問題仍然存在,但是我終於抓住了解決方案。

包括,

android:windowSoftInputMode="adjustPan|adjustResize" 進入您的活動,該活動AndroidManifest.xml 托管片段

如果使用鍵盤/數字鍵盤,則布局不會移位。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM