当键盘打开时,我尝试以不同的方式设置片段的调整,但目前我没有积极的结果。在此处输入代码
目标是仅重新调整两个片段中的一个。
这是一个例子
活动
public class MainActivity extends Activity {
...
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (savedInstanceState == null) {
getFragmentManager().beginTransaction()
.add(R.id.frame1, new PlaceholderFragment())
.commit();
getFragmentManager().beginTransaction()
.add(R.id.frame2, new PlaceholderFragment1())
.commit();
}
}
...
片段:
public static class PlaceholderFragment extends Fragment {
public PlaceholderFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Context contextThemeWrapper = new ContextThemeWrapper(getActivity(), R.style.noresize);
// LayoutInflater localInflater = inflater.cloneInContext(contextThemeWrapper);
getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING);
return inflater.inflate(R.layout.fragment_main, container, false);
}
}
public static class PlaceholderFragment1 extends Fragment {
public PlaceholderFragment1() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
View rootView = inflater.inflate(R.layout.fragment_main_2, container, false);
return rootView;
}
}
Activity的主要布局:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
tools:ignore="MergeRootFrame"
android:orientation="horizontal"
>
<FrameLayout
android:id="@+id/frame1"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent">
<FrameLayout
android:id="@+id/frame2"
android:background="#30000000"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent">
</LinearLayout>
好的,看到我在活动上重新定义了两次 SoftInputMode,这不太可能成功。那么,是否可以做类似 fragment.getWindows.setSoftInputMode (...
对不起我的英语不好 ...