如果我理解您的问题正确,您想要一个带有背景和滚动视图的布局。当软键盘弹出时,您想要调整滚动视图的大小,但保持背景全尺寸,对吗?如果是这样,那么我可能已经找到了一个解决此问题的方法:
您可以创建2个活动。
活动1:
public class StartActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent StartApp = new Intent(this, DialogActivity.class);
startActivity(StartApp);
setContentView(R.layout.start);
}
}
Activity2:
public class DialogActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.dialog);
Drawable d = new ColorDrawable(Color.BLACK);
d.setAlpha(0);
getWindow().setBackgroundDrawable(d);
}
}
开始布局:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/test"> //your background
</LinearLayout>
对话框布局:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent"
android:layout_width="fill_parent">
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
</LinearLayout>
</ScrollView>
</RelativeLayout>
AndroidManifest.xml
启动 Activity:
android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
对话框活动
android:theme="@android:style/Theme.Dialog"
android:windowSoftInputMode="adjustResize"
android:excludeFromRecents="true"
编辑:要立即完成活动,请在DialogActivity中的某处使用以下代码(例如,重写返回按钮):
@Override
public void onBackPressed() {
Intent intent = new Intent(getApplicationContext(), StartActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.putExtra("EXIT", true);
startActivity(intent);
}
在StartActivity的onCreate()
方法中:
if (getIntent().getBooleanExtra("EXIT", false)) {
finish();
}
else {
Intent StartApp = new Intent(this, TestActivity.class);
startActivity(StartApp);
}
屏幕截图!
正常情况下
点击EditText框
向下滚动后(注:我把文本框放在scrollview中,所以它消失了;)
希望这能帮到你 :)
adjustPan
应该正好满足您的需求(“活动的主窗口不会被调整大小以为软键盘腾出空间。相反,窗口的内容会自动平移”),请参阅文档。您遇到了什么问题? - matiash