일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- Spring
- 선택적조인
- MySQL
- Google Map
- MFC
- Ajax
- Eclipse
- PHP
- jsr 296
- swingx
- dock
- JDOM
- JSON
- Struts
- sencha touch
- oracle
- Android
- ibsheet
- appspresso
- node.js
- phonegap
- iBATIS
- GPS
- 전자정부프레임워크
- rowspan
- 가우스
- jQuery
- WebLogic
- PLSQL
- tomcat
Archives
- Today
- Total
Where The Streets Have No Name
orientation이 변경에 따라 layout을 동적으로 변경 본문
위 이미지와 같이 layout-land, layout-port로 구분해서 작성한다.
import android.app.Activity;
import android.content.res.Configuration;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class LayoutDemoActivity extends Activity {
final static String TAG = "LayoutDemo";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Log.d(TAG, "onCreate");
init();
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
Log.d(TAG, "onConfigurationChanged");
super.onConfigurationChanged(newConfig);
switch (newConfig.orientation) {
case Configuration.ORIENTATION_PORTRAIT:
Log.d(TAG, "세로");
setContentView(R.layout.main);
break;
case Configuration.ORIENTATION_LANDSCAPE:
Log.d(TAG, "가로");
setContentView(R.layout.main);
break;
}
init();
}
private void init(){
Button button1 = (Button)findViewById(R.id.button1);
button1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Log.d(TAG, "onClick");
}
});
}
}
AndroidManifest.xml에 android:configChanges="orientation|keyboardHidden"을 추가해줘야함
위소스데로 구성하면 방향전환에 따라 main.xml을 다르게 로딩한다.
위소스는 에뮬레이터상이 아닌 실디바이스상에서만 제대로 작동함.