2009年5月26日火曜日

Android で数独 - ユーザインタフェースのレイアウト -

Android で数独を作ってみる。

Project name : Sudoku
Package name : org.example.sudoku
Activity : Sudoku
Application name : Sudoku



More...

XML でユーザインタフェースを設定しているのが
res/layout/main.xml
これを書き換えれば OK

Sudoku/res/layout/main.xml

  1. <!--xml version="1.0" encoding="utf-8"?-->  
  2. <linearlayout <brbr="">xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:orientation="vertical"  
  4.     android:layout_width="fill_parent"  
  5.     android:layout_height="fill_parent"  
  6.     >  
  7. <textview <brbr="">    android:layout_width="fill_parent"   
  8.     android:layout_height="wrap_content"   
  9.     android:text="@string/main_title"  
  10.     />  
  11. <button  
  12.     android:layout_width="fill_parent"  
  13.     android:layout_height="wrap_content"  
  14.     android:text="@string/continue_label"  
  15.     />  
  16. <button  
  17.     android:layout_width="fill_parent"  
  18.     android:layout_height="wrap_content"  
  19.     android:text="@string/new_game_label"  
  20.     />  
  21. <button  
  22.     android:layout_width="fill_parent"  
  23.     android:layout_height="wrap_content"  
  24.     android:text="@string/about_label"  
  25.     />  
  26. <button  
  27.     android:layout_width="fill_parent"  
  28.     android:layout_height="wrap_content"  
  29.     android:text="@string/exit_label"  
  30.     />  
  31. </button  
  32. </button  
  33. </button  
  34. </button  
  35. </textview></linearlayout>  






もう少しカスタマイズ

Sudoku/res/layout/main.xml

  1. <!--xml version="1.0" encoding="utf-8"?-->  
  2. <linearlayout <brbr="">xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:background="@color/background"  
  4.     android:orientation="horizontal"  
  5.     android:layout_width="fill_parent"  
  6.     android:layout_height="fill_parent"  
  7.     android:padding="30dip"  
  8. >  
  9. <linearlayout  
  10.     android:layout_width="fill_parent"  
  11.     android:layout_height="wrap_content"  
  12.     android:layout_gravity="center"  
  13.     android:orientation="vertical"  
  14. >    
  15. <textview <brbr="">    android:layout_width="wrap_content"   
  16.     android:layout_height="wrap_content"   
  17.     android:text="@string/main_title"  
  18.     android:layout_gravity="center"  
  19.     android:layout_marginBottom="25dip"  
  20.     android:textSize="24.5sp"  
  21.     />  
  22. <button  
  23.     android:id="@+id/continue_button"  
  24.     android:layout_width="fill_parent"  
  25.     android:layout_height="wrap_content"  
  26.     android:text="@string/continue_label"  
  27.     />  
  28. <button  
  29.     android:id="@+id/new_button"  
  30.     android:layout_width="fill_parent"  
  31.     android:layout_height="wrap_content"  
  32.     android:text="@string/new_game_label"  
  33.     />  
  34. <button  
  35.     android:id="@+id/about_button"  
  36.     android:layout_width="fill_parent"  
  37.     android:layout_height="wrap_content"  
  38.     android:text="@string/about_label"  
  39.     />  
  40. <button  
  41.     android:id="@+id/exit_button"  
  42.     android:layout_width="fill_parent"  
  43.     android:layout_height="wrap_content"  
  44.     android:text="@string/exit_label"  
  45.     />  
  46. </button  
  47. </button  
  48. </button  
  49. </button  
  50. </textview></linearlayout  
  51. </linearlayout>   


Sudoku/res/values/colors.xml

  1. <!--xml version="1.0" encoding="utf-8"?-->  
  2. <resources>  
  3.  <color name="background">#3500ffff</color>  
  4. </resources>  




横長モードだとはみ出してしまう
ちなみにエミュレータで横長モードにするには Ctrl + F11



ので、横長用のレイアウトを作る

Sudoku/res/layout-land/main.xml

  1. <!--xml version="1.0" encoding="utf-8"?-->  
  2. <linearlayout  
  3.  xmlns:android="http://schemas.android.com/apk/res/android"  
  4.  android:background="@color/background"  
  5.  android:layout_height="fill_parent"  
  6.  android:layout_width="fill_parent"  
  7.  android:padding="15dip"  
  8.  android:orientation="horizontal"  
  9. >  
  10. <linearlayout <brbr=""> android:orientation="vertical"  
  11.  android:layout_height="wrap_content"  
  12.  android:layout_width="fill_parent"  
  13.  android:layout_gravity="center"  
  14.  android:paddingLeft="20dip"  
  15.  android:paddingRight="20dip"  
  16. >  
  17. <textview  
  18.  android:text="@string/main_title"  
  19.  android:layout_height="wrap_content"  
  20.  android:layout_width="wrap_content"  
  21.  android:layout_gravity="center"  
  22.  android:layout_marginBottom="20dip"  
  23.  android:textSize="24.5sp"   
  24. />  
  25. <tablelayout  
  26.  android:layout_height="wrap_content"  
  27.  android:layout_width="wrap_content"  
  28.  android:layout_gravity="center"  
  29.  android:stretchColumns="*"  
  30. >  
  31. <tablerow>  
  32. <button  
  33.  android:id="@+id/continue_button"  
  34.  android:text="@string/continue_label"  
  35. />  
  36. <button  
  37.  android:id="@+id/new_button"  
  38.  android:text="@string/new_game_label"  
  39. />  
  40. </button  
  41. </button  
  42. </tablerow>  
  43. <tablerow>  
  44. <button  
  45.  android:id="@+id/about_button"  
  46.  android:text="@string/about_label"  
  47. />  
  48. <button  
  49.  android:id="@+id/exit_button"  
  50.  android:text="@string/exit_label"  
  51. />  
  52. </button  
  53. </button  
  54. </tablerow>  
  55.   
  56. </tablelayout  
  57. </textview  
  58. </linearlayout>  
  59.   
  60.   
  61. </linearlayout  


直った



0 件のコメント:

コメントを投稿