menu


2016年5月28日土曜日

アンドロイドアプリ開発:各要素定義


各要素定義

各要素定義とは
レイアウトやGUIに指定するパラメータです。
入出力ボタンなんかの部品ですね。

【各要素定義】

android:gravity 表示位置設定(レイアウト内のどこに表示するかを指定する)
レイアウトで指定すると、内部のDUIにも適用される。
android:layout_gravity 表示位置設定(レイアウト内のどこに表示するかを指定する)
設定した物にのみ適用される。


指定値 効果
topコンテナの上部に配置
bottomコンテナの下部に配置
rightコンテナの左側に配置
leftコンテナの右側に配置
fillオブジェクトの高さ・幅を、コンテナのサイズに合わせる
fill_verticalオブジェクトの高さをコンテナのサイズに合わせる
fill_horizontalオブジェクトの幅をコンテナのサイズに合わせる
centerオブジェクトを中央に配置する。サイズ変更無し
center_verticalオブジェクトを上下中央に配置しする。サイズ変更無し
center_horizontalオブジェクトを左右中央に配置する。サイズ変更無し
clip_verticaltop/bottomの追加オプションとして、オブジェクトの上部/下部の
境界をコンテナの境界に合わせます
clip_horizontalleft/rightの追加オプションとして、オブジェクトの左側/右側の
境界をコンテナの境界に合わせます


android:layout_width 表示横幅を指定します
android:layout_height 表示縦幅を指定します


指定値 効果
fill_parent
(match_parent同じ)
最大可能幅・高さで表示
wrap_content最小表示幅・高さで表示


android:layout_weight 表示割合を設定します
1をボタンに設定し、3個ボタンを定義すると、各ボタンの幅が1/3で表示されます。
2・1・1で定義すると、2/4・1/4・1/4で表示されます。


指定値 効果
fill_parent
(match_parent同じ)
最大可能幅・高さで表示
wrap_content最小表示幅・高さで表示


android:layout_above 指定したViewの上部とこのViewの下部を合わせるように配置します。
android:layout_alignBaseline 指定したViewのベースラインに合わせて配置します。
android:layout_alignTop 指定したViewの上方向に配置します。
android:layout_alignBottom 指定したViewの下方向に配置します。
android:layout_alignLeft 指定したViewの左方向に配置します。
android:layout_alignRight 指定したViewの右方向に配置します。
android:layout_alignParentTop 親の上方向に配置します。
android:layout_alignParentBottom 親の下方向に配置します。
android:layout_alignParentLeft 親の左方向に配置します。
android:layout_alignParentRight 親の右方向に配置します。
android:layout_alignWithParentIfMissing 親がアンカーとして使われるとき、アンカーはlayout_toLeftOf,
layout_toRightOfなどを受け付けません。
android:layout_below 指定したViewの下部とこのViewの上部を合わせるように配置します。
android:layout_centerHorizontal 子Viewの水平配置を親Viewの幅に対して中央となるように配置します。
android:layout_centerInParent 親の水平方向の中央に配置します。
android:layout_centerVertical 子Viewの上下配置を親Viewの幅に対して中央となるように配置します。
android:layout_toLeftOf 指定したViewの左端とViewの右端を合わるように配置します。
android:layout_toRightOf 指定したViewの右端とViewの左端を合わるように配置します。


android:stretchColumnsここに指定した列は、行の空いているスペースいっぱ
いに広がる。この属性の値は単一の列番号またはコンマ区切りの列番号のリストで指定す
る。列番号は左の列から 0 から振られる
android:shrinkColumnsここに指定した列は、コンテンツを折り返して表示する
この属性の値は単一の列番号またはコンマ区切りの列番号のリストで指定す
る。列番号は左の列から 0 から振られる


android:padding内部に取られる余白サイズを指定する
上下左右全てに共通値
android:paddingTop内部上部に取られる余白サイズを指定する
android:paddingBottom内部下に取られる余白サイズを指定する
android:paddingLeft内部左に取られる余白サイズを指定する<
android:paddingRight内部右に取られる余白サイズを指定する
layout_margin外部左上右下に取られる余白を指定する
layout_marginTop外部上に取られる余白を指定する
layout_marginBottom外部下に取られる余白を指定する
layout_marginLeft外部左に取られる余白を指定する
layout_marginRight外部右に取られる余白を指定する


2016年5月26日木曜日

アンドロイドアプリ開発:GUIコンポーネント


GUIコンポーネント

GUIコンポーネントとは
簡単に言うと、ボタンとかのグラフィカルユーザインターフェース
入出力ボタンなんかの部品ですね。
以下の上3つは、チャイルドフレームとして使えます。
WebView・SurfaceViewについては、不明です。調査不足でごめんなさい。

【GUIコンポーネント】

ListView 複数のデータを一覧表示する時などに使用します。
ScrollView 横方向にスクロールするビューです
HorizontalScrollView 縦方向にスクロールするビューです
WebView
(ウェーブビュー)
Web画面表示用ビューです。ネットサイトの表示に使用してください。
SurfaceView スレッド内での描画処理をするビューです。
ムービー再生やカメラなど、定期的に再描画を必要な場合に使用します。
EditText Text入力用部品
Button ボタン
TextView テキスト出力
DatePicker 日付を入力するための部品です。アプリを使う中でよく目にするのではないでしょうか。
SeekBar ある一定の範囲で数値を入力するときに便利な部品です。
つまみをドラッグすることで値を入力することができます。
RatingBar レート(評価)を入力させたい場合に使います
RadioButton 複数の選択肢の中から一つを選択させたい場合に使います
Switch オンオフの状態を表す部品です。視覚的に状態が分かりやすいため、
設定画面などで用いられることが多いです
ImageView 画像を表示するための部品です
WebView Webページを表示するための部品です
ToggleButton トグルボタン押す度にONとOFFを切り替えるボタンです
CheckBox チェックボックス

2016年5月22日日曜日

アンドロイドアプリ開発:レイアウト


レイアウトについてまとめてみました。
これは、私の買った本には全てが載っていないので、ネットで検索して抜粋してまとめました。

レイアウトとは
携帯画面のベースとなる表示エリアの形式を現します。
一番外枠になるレイアウトを良くルートと呼ぶらしいです。
レイアウトの中にレイアウトを入れて親と子の関係で良く使用されます。
イメージ

【レイアウト】

LinearLayout
(リニアレイアウト)
縦向きまたは横向きに一直線にウィジェットを並べるレイアウト縦一列に並べるには、android:orientation="vertical"と指定します。
指定の無い時は、こちらになります。横に並べるにはandroid:orientation="horizontal"と指定します。
また、画面いっぱいに分割することも可能で、android:layout_weight="1"で画面を自動で分割してくれます。
RelativeLayout
(リラティブレイアウト)
相対的な位置指定をするレイアウト。また,上端や下端にレイアウトするといった指定を行うことも可能android:layout_alignParentLeft = "true" 左 親レイアウトの左側に配置します。
android:layout_alignParentRight = "true" 右 親レイアウトの右側に配置します。
android:layout_alignParentTop = "true" 上 親レイアウトの上側に配置します。
android:layout_alignParentBottom = "true" 下 親レイアウトの下側に配置します。
android:layout_centerInParent = "true" 中央 親レイアウトの中央に配置します。
※ 上と左を指定すると、左上となります。
AbsoluteLayout
(アブソレートレイアウト)
配置を絶対座標で指定するレイアウト。android:layout_x = "100dp" X座標を指定します。
android:layout_y = "100dp" Y座標を指定します。
TableLayout
(テーブルレイアウト)
View (テキスト・画像・ボタン等) を表形式でレイアウトするためのものです。
GridLayout
(グリッドレイアウト)
android:columnCount 横方向のマスの数 
android:rowCount 縦方向のマスの数 
FrameLayout
(フレームレイアウト)
後から配置したウィジェットが前面に描画されるレイアウトです。
FrameLayoutとは、パーツをひとつだけ配置して使用するレイアウトです。
位置の指定はできず、FrameLayoutに配置したパーツは左上に表示されます。
また、FrameLayoutに複数のパーツを配置した場合、パーツが重なって表示されます。




2016年5月19日木曜日

アンドロイドアプリ開発:静的と動的について!


静的と動的ってわかりますか?

アンドロイドアプリを作成する時に、ボタンを配置します。XMLファイルに定義して、画面を作成するのが、静的生成と言われ、javaブログラムで作成するのが、動的生成と言われます。
固定数配置する場合は、静的生成し、変動する数分配置するときは、動的に生成します。
基本は、静的生成で作成されますが、アプリによっては、動的生成が必要になります。
まずは、静的生成に必要な情報を順次展開して行くつもりです。

アンドロイドアプリは、レイアウトと言われるパーツの上にGUI(ボタンとか)と言われるパーツをのせて、画面を作成していきます。
レイアウトの上には、さらにレイアウトを乗せる事ができます。
画用紙の上に小さい画用紙を乗せるようなイメージです。
このレイアウトには、何種類かの種類があり、用途に合わせて組み合わせを換えて画面を構成します。
縦並びになるレイアウトや横並びになるレイアウトなどです。
GUIには、表示に使うビューと入力に使うボタン系があり、それの組み合わせと、表示パラメーターの設定で画面を作成します。
基本は、こんな感じです。
つぎは、レイアウトの種類を一覧で教えます。
私も、資料が無いので、全てかどうかわかりませんが、ネットから、いろいろ検索して、まとめてみました。次回公開します。

2016年5月18日水曜日

単位について


アンドロイドアプリの作成の際に、良く記載されてる単位です。

px ピクセルを表します。画面は全て点で構成されます。この1つの点を示すのが、pxです。
しかし、あまりアプリ開発では、使わないようにしましょう。

dp(dip) 密度非依存ピクセルこれは、解像度に合わせて1dpが、1px × 1pxだったり、1.5px × 1.5pxだったりします。
こらにより、使用携帯が変わっても同じ表示になる単位です。これを使うことにより、いろいろな画面サイズの携帯でも、同じ表示が、実現できます。

少し、初心に返ってやり直しましょう!

アンドロイドアプリを始めて、少し経験が、あるので、ボタン表示とかしましたが、その後、ボタン間隔が上手くいきません。

少し初心に返って情報を整理しましょう。

基本から少しづつやらないと、全然役に立ちません。

ここ何日か、ボタン間隔で悩み続けました。

ネットでも、検索して、いろいろ試してみました。

前にやった時は、ツールが自動で設置してくれたので、全然意識してませんでしたが、手動で設置するのは、なかなか情報が見つかりません。

そこで、情報を整理しながら、少しづつ進めていきます。

今回は、ツールはありません!

ひとつひとつを確実に設置していかなければいけません。

私も、わからなくなりますし、ここを見た方も、解らないと思います。

一歩一歩着実に覚えて行きましょう!

2016年5月16日月曜日

昨日本をもう1冊買いました。

アンドロイドアプリを作ろうと思って簡単かな?

なんて考えてましたが、結構大変です。

思ったイメージの画面を作るには、結構てまが掛かります。

情報も、少ないし、実現方法がわかりません。

さそこで、ネットの情報と本の情報を使って進める予定てみす。

以下の本は、ラインや四角丸などの描写の書き方があったので、購入しました。


Androidプログラミングバイブル [ 布留川英一 ]
価格:3218円(税込、送料無料)

実際に使ってみました。

エラーもなく書けますが、そのままでは、動きません。

バージョンとかの関係なのかわかりませんが、ネットから情報を調べて、書き方を代えたら出力されました。

描写とボタンの併用が、良くわからず、まだ勉強中です。

もう少しわかったら、次のソースを投稿します。


2016年5月14日土曜日

TableLayoutを使ってみる


TableLayoutを使ってみる。

これは、画面上に表みたいな出力をするレイアウト定義!
私は、カレンダーを作る予定で調べながら作成しています。
以下にソースを載せます。
ファイル:strings.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>

    <string name="app_name">Calendar</string>
    <string name="hello_world">こんにちは まりね world!</string>
    <string name="sunday">日</string>
    <string name="monday">月</string>
    <string name="tuesday">火</string>
    <string name="wednesday">水</string>
    <string name="thursday">木</string>
    <string name="friday">金</string>
    <string name="saturday">土</string>
</resources>
表示用に、曜日の文字列を追加してみた。


ファイル:main.xml
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent"
 android:layout_height="fill_parent" 
   android:background="#ffeeff"
   android:weightSum="7">
  <TableRow>
    <TextView
        android:text="@string/sunday"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:gravity="center"
        android:textColor="#ff0000" />
      <TextView
        android:text="@string/monday"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:gravity="center"
        android:textColor="#000000"  />
      <TextView
        android:text="@string/tuesday"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:gravity="center"
        android:textColor="#000000" />
      <TextView
        android:text="@string/wednesday"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:gravity="center"
        android:textColor="#000000" />
      <TextView
        android:text="@string/thursday"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:gravity="center"
        android:textColor="#000000" />
       <TextView
        android:text="@string/friday"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:gravity="center"
        android:textColor="#000000" />
      <TextView
        android:text="@string/saturday"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:gravity="center"
        android:textColor="#0000ff" />
</TableRow> 
  <TableRow>
  <Button
android:text="00"
android:id="@+id/button1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textColor="#0000ff" >
</Button>
<Button
android:text="00"
android:id="@+id/button1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textColor="#0000ff" >
</Button>
<Button
android:text="00"
android:id="@+id/button1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textColor="#0000ff" >
</Button>
<Button
android:text="00"
android:id="@+id/button1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textColor="#0000ff" >
</Button>
<Button
android:text="00"
android:id="@+id/button1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textColor="#0000ff" >
</Button>
<Button
android:text="00"
android:id="@+id/button1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textColor="#0000ff" >
</Button>
<Button
android:text="00"
android:id="@+id/button1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textColor="#0000ff" >
</Button>
</TableRow> 
  <TableRow>
  <Button
android:text="00"
android:id="@+id/button1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textColor="#0000ff" >
</Button>
<Button
android:text="00"
android:id="@+id/button1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textColor="#0000ff" >
</Button>
<Button
android:text="00"
android:id="@+id/button1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textColor="#0000ff" >
</Button>
<Button
android:text="00"
android:id="@+id/button1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textColor="#0000ff" >
</Button>
<Button
android:text="00"
android:id="@+id/button1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textColor="#0000ff" >
</Button>
<Button
android:text="00"
android:id="@+id/button1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textColor="#0000ff" >
</Button>
<Button
android:text="00"
android:id="@+id/button1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textColor="#0000ff" >
</Button>
</TableRow> 
  <TableRow>
  <Button
android:text="00"
android:id="@+id/button1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textColor="#0000ff" >
</Button>
<Button
android:text="00"
android:id="@+id/button1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textColor="#0000ff" >
</Button>
<Button
android:text="00"
android:id="@+id/button1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textColor="#0000ff" >
</Button>
<Button
android:text="00"
android:id="@+id/button1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textColor="#0000ff" >
</Button>
<Button
android:text="00"
android:id="@+id/button1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textColor="#0000ff" >
</Button>
<Button
android:text="00"
android:id="@+id/button1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textColor="#0000ff" >
</Button>
<Button
android:text="00"
android:id="@+id/button1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textColor="#0000ff" >
</Button>
</TableRow> 
  <TableRow>
  <Button
android:text="00"
android:id="@+id/button1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textColor="#0000ff" >
</Button>
<Button
android:text="00"
android:id="@+id/button1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textColor="#0000ff" >
</Button>
<Button
android:text="00"
android:id="@+id/button1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textColor="#0000ff" >
</Button>
<Button
android:text="00"
android:id="@+id/button1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textColor="#0000ff" >
</Button>
<Button
android:text="00"
android:id="@+id/button1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textColor="#0000ff" >
</Button>
<Button
android:text="00"
android:id="@+id/button1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textColor="#0000ff" >
</Button>
<Button
android:text="00"
android:id="@+id/button1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textColor="#0000ff" >
</Button>
</TableRow> 
  <TableRow>
  <Button
android:text="00"
android:id="@+id/button1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textColor="#0000ff" >
</Button>
<Button
android:text="00"
android:id="@+id/button1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textColor="#0000ff" >
</Button>
<Button
android:text="00"
android:id="@+id/button1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textColor="#0000ff" >
</Button>
<Button
android:text="00"
android:id="@+id/button1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textColor="#0000ff" >
</Button>
<Button
android:text="00"
android:id="@+id/button1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textColor="#0000ff" >
</Button>
<Button
android:text="00"
android:id="@+id/button1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textColor="#0000ff" >
</Button>
<Button
android:text="00"
android:id="@+id/button1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textColor="#0000ff" >
</Button>
</TableRow> 
</TableLayout>      
ソースは、曜日の表示と日付にわかれます。
説明
 android:weightSum="7"
 1行を7とします。
 曜日数が7なので、このように指定しました。
 android:layout_width="0dp"
 表示幅が不明なので、0としました。
 android:layout_weight="1"
 表示列の幅を1(1/7)を指定。
 <TableRow>
 行の開始
 </TableRow>
 行の終わり

実行してみました。
ちょっと予定と違う!
違うアプローチを考えてみます。