我创建了这个生成 EditText 表的应用程序。这是布局的分隔参数的代码部分。
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
setContentView(R.layout.seconda);
Bundle extras = getIntent().getExtras();
N = extras.getInt("dim_matrice");//dimensione della matrice
setKeys();
values = new EditText[N][N];
salvatore = new EditText[N*N];
FrameLayout frameLayout = new FrameLayout(this);
frameLayout.setLayoutParams(new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
HorizontalScrollView HSC = new HorizontalScrollView(this);
HSC.setLayoutParams(new FrameLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, Gravity.CENTER));
frameLayout.setBackgroundResource(R.drawable.lavagna);
ScrollView VSC = new ScrollView(this);
VSC.setLayoutParams(new FrameLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
TableLayout tableLayout = new TableLayout(this);
tableLayout.setLayoutParams(new FrameLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
for ( int i = 0; i < N; i++) {
tableRow = new TableRow(this);
tableRow.setGravity(Gravity.CENTER);
for (int j = 0; j < N; j++) {
values[i][j] = new EditText(this);
values[i][j].setHint(i1 + " " + j1);
values[i][j].setPadding(10, 10, 10, 10);
salvatore[sal] = valore[i][j];
tableRow.addView(valore[i][j]);
j1++;
if (j1 == (N+1)){
j1 = 1;
}
sal++;
}
tableLayout.addView(tableRow);
i1++;
if (i1 == (N+1)){
i1 = 1;
}
}
for (i=0;i<N*N;i++){
InputMethodManager imm = (InputMethodManager)getSystemService(
Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(salvatore[i].getWindowToken(), 0);
salvatore[i].setInputType(0);
salvatore[i].setOnTouchListener(this);
salvatore[i].setOnClickListener(this);
hideDefaultKeyboard();
enableKeyboard();
}
VSC.addView(tableLayout);
HSC.addView(VSC);
frameLayout.addView(HSC);
setContentView(frameLayout);
此代码在屏幕中央显示 EditText 表。这个应用程序关闭了默认键盘来激活我单独创建的地雷。这是我将键盘包含在 relativeLayout 中的代码。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/xK1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:screenOrientation="portrait" >
<include android:id="@+id/xKeyBoard" layout="@layout/keyboard"></include>
</RelativeLayout>
我希望我的键盘显示与默认值相同。所以我想把它正确地包含在布局法中。