More Games - PAINONE

Android games

sites.google.com

단말기 해상도 구하기
 
Display display = ((WindowManager)context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
int width = display.getWidth();
int height = display.getHeight();
 
위 방법으로 구한 해상도는 단말기 해상도이지 View의 해상도가 아니다.
실제 단말기에 제목 표시줄/상태 표시줄 등이 50~70px 정도를 차지하므로 프로그램을 작성할때 감안하여 처리.
 
View의 높이를 단말기 해상도 높이와 같이 설정하면 View의 하단부분이 잘려진다.
또 Touch이벤트 핸들러를 작성하는 위치에 따라 View가 기준이 아니라 화면 전체를 기준으로 해서
좌표를 구하는 경우 Touch 이벤트에서 구한 세로 좌표가 View의 세로좌표에서 50~70px차이가 난다.
 
쉽게 문제를 해결하는 방법으로 Full Screen모드로 설정하기
AndroidManifest 설정방법
activity에 Theme속성
android:theme="@android:style/Theme.NoTitleBar.Fullscreen" 상태표시줄/제목표시줄 제거
android:theme="@android:style/Theme.NoTitleBar"	제목 표실줄 제거
 
Java Code 설정방법
// 상태표시줄 제거(Full Screen으로 하더라도 제목표시줄은 남는다.)
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
// 제목 표시줄 제거
requestWindowFeature(Window.FEATURE_NO_TITLE);

'Android > Develop' 카테고리의 다른 글

AutoCompleteTextView 리스트 클릭 이벤트  (0) 2011.02.01
 

More Games - PAINONE

Android games

sites.google.com

 

More Games - PAINONE

Android games

sites.google.com

AutoCompleteTextView 구현과 리스트 클릭 이벤트

main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
	android:orientation="vertical"
	android:layout_width="fill_parent"
	android:layout_height="fill_parent"
	>
	<AutoCompleteTextView
		android:id="@+id/autoComplete"
		android:layout_width="fill_parent"
		android:layout_height="wrap_content"
		/>
	<TextView
		android:id="@+id/textView"
		android:layout_width="fill_parent"
		android:layout_height="wrap_content"
		/>
</LinearLayout>​
package exam.AutoComplete;

import android.app.*;
import android.content.*;
import android.os.*;
import android.view.*;
import android.view.inputmethod.*;
import android.widget.*;
import android.widget.AdapterView.OnItemClickListener;

public class AutoComplete extends Activity {
	private String[] COUNTRIES = new String[] {
		"asp.net",
		"php",
		"java",
		"javascript",
		"flex",
		"actionscript",
		"jsp"
	};
	
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
        
		AutoCompleteTextView autoComplete = (AutoCompleteTextView)findViewById(R.id.autoComplete);
		ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line, COUNTRIES);
		autoComplete.setAdapter(adapter);
		// AutoCompleteTextView 자동완성 리스트에 클릭 이벤트
		autoComplete.setOnItemClickListener(new OnItemClickListener() {
			public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
				AutoCompleteTextView autoComplete = (AutoCompleteTextView)findViewById(R.id.autoComplete);
				TextView textView = (TextView)findViewById(R.id.textView);
				textView.setText(autoComplete.getText());
				// 열려있는 키패드 닫기
				InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
				imm.hideSoftInputFromWindow(autoComplete.getWindowToken(), 0);
			}
		});
	}
}
​

리스트 스타일을 바꿔보자.
레이아웃 xml파일을 새로 만들고 아래와 같이 작성
auto_complete_list.xml

<?xml version="1.0" encoding="utf-8"?>
<TextView
	xmlns:android="http://schemas.android.com/apk/res/android"
	android:layout_width="fill_parent"
	android:layout_height="wrap_content"
	android:textSize="7pt"
	android:textColor="#FF0000"
	android:padding="6px"
	/>
​

아래 소스 부분을

ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line, COUNTRIES);
​

새로 만든 레이아웃으로 변경

ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.auto_complete_list, COUNTRIES);
​

'Android > Develop' 카테고리의 다른 글

단말기 해상도 구하기  (0) 2011.03.12
 

More Games - PAINONE

Android games

sites.google.com

+ Recent posts