在項(xiàng)目開發(fā)中,
成都網(wǎng)站建設(shè)、網(wǎng)站制作的關(guān)注點(diǎn)不是能為您做些什么網(wǎng)站,而是怎么做網(wǎng)站,有沒有做好網(wǎng)站,給創(chuàng)新互聯(lián)建站一個展示的機(jī)會來證明自己,這并不會花費(fèi)您太多時間,或許會給您帶來新的靈感和驚喜。面向用戶友好,注重用戶體驗(yàn),一切以用戶為中心。
關(guān)于android手機(jī)橫豎屏切換時顯示不同的界面,在這里我定義了兩個xml布局文件
landscape_screen.xml,portrait_screen.xml
根據(jù)屏幕的旋轉(zhuǎn)切換不同的布局文件
重寫onConfigurationChanged方法,對其進(jìn)行監(jiān)聽并判斷當(dāng)前的屏幕狀態(tài),根據(jù)其狀態(tài)顯示對應(yīng)的布局文件
當(dāng)然在manifest.xml中對應(yīng)的activity中要加上
android:configChanges="keyboardHidden|orientation|screenSize">
貼上代碼說話
public classScreenActivity extends Activity implements OnClickListener{
private Button btn;
@Override
protected voidonCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//默認(rèn)為豎屏
setupViewInPortraitLayout();
}
//豎屏界面
private voidsetupViewInPortraitLayout(){
setContentView(R.layout.portrait_screen);
btn = (Button)findViewById(R.id.button1_portrait);
btn.setOnClickListener(this);
}
//橫屏界面
private voidsetupViewInLandscapeLayout(){
setContentView(R.layout.landscape_screen);
btn = (Button)findViewById(R.id.button1_landscape);
btn.setOnClickListener(this);
}
@Override
public voidonConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
Toast.makeText(ScreenActivity.this,"onConfigurationChanged", Toast.LENGTH_LONG).show();
Configuration cfg =getResources().getConfiguration();
if (cfg.orientation ==Configuration.ORIENTATION_LANDSCAPE) {
setupViewInLandscapeLayout();
} else if(cfg.orientation == Configuration.ORIENTATION_PORTRAIT) {
setupViewInPortraitLayout();
}
}
@Override
public void onClick(Viewarg0) {
// TODO Auto-generatedmethod stub
if(arg0.equals(btn)){
Toast.makeText(ScreenActivity.this,"Click", Toast.LENGTH_LONG).show();
}
}
}
//landscape_screen.xml
"1.0"encoding="utf-8"?>
"http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">