2012-12-16 90 views
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佈局被轉移了,當我選擇輸入一些東西。

如何解決這一問題?

回答

0

好的。沒關係。我遇到了問題。

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

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

包括

android:windowSoftInputMode="adjustPan|adjustResize"到您的活動哪些主機在AndroidManifest.xml

佈局片段(S)如果使用鍵盤/數字鍵盤不會移位。