我想做出一個適合所有智能手機的全屏模式。下面這段代碼創建一個tablelayout布局,可以水平和垂直滾動。同時想把 edittext矩陣集放在布局的中間位置。怎麼實現這個功能?
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.seconda);
HorizontalScrollView HSC = new HorizontalScrollView(this);
ScrollView VSC = new ScrollView(this);
VSC.setBackgroundResource(R.drawable.lavagna_psd);
tableLayout = new TableLayout(this);
tableLayout.setGravity(Gravity.CENTER);
values = new EditText[3][3];
for (int i = 0; i < 3; i++) {
tableRow = new TableRow(this);
tableRow.setGravity(Gravity.CENTER);
for (int j = 0; j < 3 ; j++) {
values[i][j] = new EditText(this);
values[i][j].setHint("r: " + (i) + " " + "c: " + (j));
values[i][j].setPadding(10, 10, 10, 10);
tableRow.addView(values[i][j]);
}
tableLayout.addView(tableRow);
}
VSC.addView(tableLayout);
HSC.addView(VSC);
setContentView(HSC);
}
你可以在xml配置或java代碼中設置全屏
在目錄res/values下創建自定義的styles.xml。
<style name="Theme.CustomizedFullScreen" parent="android:Theme">
<item name="android:windowFullscreen">true</item>
<item name="android:windowNoTitle">true</item>
</style>
在 menifest文件中
android:theme="@style/Theme.CustomizedFullScreen"
onCreate()創建後,在activity的java文件中也可以這樣創建
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);