忍者ブログ
  • 2025.03
  • 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
  • 29
  • 30
  • 2025.05
[PR]
×

[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。

【2025/04/20 06:21 】 |
RelativeLayout
RelativeLayout
自由な配置を指定できるレイアウト。


============================================
RelativeLayout
リファレンス

gravity
いつもと同じ。

ignoreGravity
gravityを無視させるオブジェクトを1つだけ指定できる。(対応するsetIgnoreMethod()の形からして、1つしか指定できないようだ)





<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:gravity="right"
android:ignoreGravity="@+id/imageView11"
tools:context="com.example.layoutmaster.MainActivity" >

<ImageView
android:id="@+id/imageView11"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:src="@drawable/ic_launcher" />

<ImageView
android:id="@+id/imageView12"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/imageView11"
android:src="@drawable/ic_launcher" />

<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/imageView11"
android:layout_below="@+id/imageView11"
android:layout_marginTop="41dp"
android:background="#ff0"
android:orientation="vertical" >

<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="10"
android:src="@drawable/ic_launcher" />

<ImageView
android:id="@+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="20"
android:src="@drawable/ic_launcher" />

</LinearLayout>
</RelativeLayout>






PR
【2014/08/29 01:17 】 | Android | 有り難いご意見(0)
LinearLayout
LinearLayout
縦か横に単に並べるレイアウトグループ。

Eclipse上のGraphical Layoutで追加すると、以下のようにXMLが生成される。
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="127dp"
android:orientation="vertical" >

================================================================

LinearLayout

LinearLayout自体への指定。
リファレンス

orientation
並べる向き。horizontal か vertical

gravity
配置位置
fill デフォルト。内部に配置するオブジェクトの幅・高さをコンテナに合わせる
top 上に寄せる(オブジェクトのサイズはそのまま)。bottom,left,rightも同様
center 中央に寄せる(サイズはそのまま)
center_vertical 上下位置の中央に寄せる(サイズはそのまま)center_horizontalも同様
fill_vertical 上下をコンテナサイズに合わせる。らしいがどうも効かないようだ。fill_horizontalも同様


デフォルト(fill)。左上寄せになる


android:gravity="right"


android:gravity="right|bottom" パイプで繋いで複数指定可能


android:gravity="center"



baselineAligned
内部のオブジェクトのベースラインを揃える。
ベースライン…テキストのベースラインのことのようだ。


================================================================

LinearLayout.LayoutParams

リファレンス
LinearLayoutコンテナ内のオブジェクトへの指定に使う要素。

layout_gravity
配置方向。gravityと同じく、top,left,right,bottomなど。
ただし、orientation="horizontal" のときはtop,bottom、orientation="vertical"のときはleft,rightしか効かない。

また、fill_系はなぜか使えないようだ。その場合は、layout_width="match_parent"またはlayout_height="match_parent"とすると横幅(縦幅)いっぱいに広がる。
(内部にImageViewを置き、android:scaleType="fitXY"にしても結局fill_horizontalは効かなかった)


layout_weight
比率を指定して配置できる。以下、android:orientation="vertical"として説明する
各オブジェクトについて

android:layout_height="0dp"
android:layout_weight="10"





という感じで指定する。高さを0dpに明示的に指定することが必須。
なぜ0dpにするかというと、layout_weightは、余白部分の重み付け分割をしている。コンテナ内にwrap_contentとか30dpとかで高さを指定したオブジェクトがあると、それが優先して配置され、残った高さ分をlayout_weightで分割する。
だから、オブジェクトを全部layout_weightで分割したいときは、全部のオブジェクトの高さを0dpにしておくことになる。
参考



<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:background="#ff0"
android:orientation="vertical"
>

<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="10"
android:src="@drawable/ic_launcher" />

<ImageView
android:id="@+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="20"
android:src="@drawable/ic_launcher" />







こんな感じで配置される。ImageViewの場合、画像サイズ自体は変化せず、ビューの範囲が調整される。




<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:background="#ff0"
android:orientation="vertical"
>

<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="10"
android:src="@drawable/ic_launcher" />

<ImageView
android:id="@+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher" />







imageView2がlayout_height="wrap_content"になっているので、それが優先される。残った余白をlayout_weightで分割している(この場合はimageView2しかないので、余白を全部まるまる使って表示している)
だからlayout_height="match_parent"を指定しているものがあると、layout_weight指定している物はいっさい表示されなくなる。(余白が0になるから)





<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:background="#ff0"
android:orientation="vertical"
android:weightSum="100" <!--- 注目!!!!!!! -->
>

<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="10"
android:src="@drawable/ic_launcher" />

<ImageView
android:id="@+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="20"
android:src="@drawable/ic_launcher" />







LinearLayoutに android:weightSum="100" を指定すると、全体のweightの指定になる。各オブジェクトのweightの合計より大きい値をセットすれば、余白が作れる。小さい値をセットすれば、オブジェクトが見切れる。




注意!LinearLayout自体が layout_height="wrap_content"だと、このweightの指定は効かなくなる。


<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:background="#ff0"
android:orientation="vertical"
>

<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="10"
android:src="@drawable/ic_launcher" />

<ImageView
android:id="@+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="20"
android:src="@drawable/ic_launcher" />









LinearLayout自体がwrap_contentだと、そもそも余白が作られないから分割しようがない、ということかと思われる。



【2014/08/28 19:44 】 | Android | 有り難いご意見(0)
layoutをマスターする
Androidのレイアウトをマスターする。

以下のページにいろいろまとまっている。
参考


レイアウトクラス


こんな感じで各レイアウトに2種類ずつクラスがあるが、
上はレイアウトクラス自体の配置やサイズの指定で(例:LinearLayout.orientaion…並べる方向)、
下は内部のオブジェクトの配置やサイズの指定に使う要素(例:RelativeLayout.LayoutParams.layout_gravity…配置の寄せる方向)が入っている。



LinearLayout自身の配置位置指定は、LinearLayoutの親コンテナの指定に依る。つまり親コンテナが例えばRelativeLayoutなら、RelativeLayoutの項を参照のこと。
layout_gravity(自身の配置位置指定)はどうも効かないようだ。



共通のレイアウトパラメータ
android:layout_marginLeft="77dp" 左のマージン指定
layout_marginRight
layout_marginTop
layout_marginBottom
layout_marginStart
layout_marginEnd


paddingは、ビューの内部に隙間を作る
paddingTop
paddingBottom
paddingLeft
paddingRight



<relativelayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/relative"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.layoutmaster.MainActivity" >

<ImageView
android:id="@+id/imageView11"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:paddingTop="10dp"
android:src="@drawable/ic_launcher" />







パディングの設定に使える単位は
参考
px (pixels),
dp (density-independent pixels),
sp (scaled pixels based on preferred font size),
in (inches),
mm (millimeters)

可視状態

可視状態には3つの状態がある。

VISIBLE 見える
INVISIBLE 見えない。非表示部分は詰めない
GONE 見えない。非表示部分を詰める

xml上で指定する場合は
android:visibility="visible"
android:visibility="invisible"
android:visibility="gone"
とする。すぐGraphicalLayoutにも反映される。デフォルトはもちろんvisible。
プログラム中で指定する場合は
view.setVisibility(View.VISIBLE);
view.setVisibility(View.INVISIBLE);
view.setVisibility(View.GONE);
となる。


残り調査するもの


TableLayout

AbsoluteLayout
情報は今もいろんなところに載っているが、API3ですでになくなっているので使うべからず。

Space
隙間を作るためのウィジェット!
Graphical LayoutのLayoutsパレットにある


単位(dpなど)の整理

プログラム中からのセット方法
【2014/08/28 19:33 】 | Android | 有り難いご意見(0)
NDKを使ってネイティブコード
JavaだけでなくC++のコードが使えるようにするには、
AndroidNDKを使います。

NDK = Native Development Kit

NDKをダウンロード
http://developer.android.com/sdk/ndk/index.html

解凍すると、android-ndk-r5bというフォルダができる。
これをDeveloper下に置く。android-sdk-mac_x86の隣だ。
この場所を$(NDK)とする。

このフォルダの中に、ndk-buildという実行ファイルがあり、これを使うとNDKのビルドができるようだ。
サンプルプロジェクトで試してみる。

$(NDK)/samples/hello-jni に移動し、
% ../../ndk-build
で、いろいろファイルが生成される。
libs/下とobj/下の libhello-jni.so というのがキモらしい。

ビルドしたら、Eclipseで
New→AndroidProject で、今のhello-jniを選択。
そのまま実行。

これで実機上で動くアプリを確認しました。
簡単だ。



ライブラリ(Cネイティブ)のほうだけを書き換えてビルドしても反映されない。
javaコードのほうを書き換えるなりして再ビルドをかける必要があります。


さて、サンプルを実行したはいいが、もちろんiPhoneでガンガン書いているコードたちを引っ越しできなければならない。
しかしネットで探してもあまり詳しく載ってない・・・? 探し方が悪いのか

自分でいろいろやってみる。

cファイルの書き換え
→コンソールで ndk-build -B (必ずリビルドするオプション)
→Eclipseでビルドかけて実行


まず、ネイティブ関数を増やしてみる
→できた。Javaから呼び出すこともできた

cファイルを2つにしてみる
→できた。Android.mkの LOCAL_SRC_FILES にも追記すること。
 2つ目のファイルの関数をJavaから呼び出すこともできた


ゲームを作るには、
イメージファイル、シェーダのロードが必要で、
タッチ入力を受け取ったり加速度センサーを使ったりする必要がある。
これらはAndroidの機能として行う必要があるが、
Androidプログラミングを一度覚える必要がある。

という訳で、NDKはいったん留め置く。
Androidプログラミングを覚える段に入ります。
【2011/04/22 02:12 】 | Android | 有り難いご意見(0) | トラックバック()
Android開発スタート
参考ページ
技術評論社。googleで最初にヒット「Android 開発」
http://gihyo.jp/dev/serial/01/androidapp/


開発環境
OSは、Windows, Mac, Linux何でもOK。
googleの配るAndroid SDKをインストール。
無料。ただし、Androidマーケットを使う際は、最初に25ドル必要。カード決済のみ。

SDKは、ここからインストール
http://developer.android.com/sdk/index.html
とりあえず、Developer/下に置いた。
フォルダ名はandroid-sdk-mac_x86
ホームディレクトリに.bash_profileを作成し、パスを通す

JDKをインストール。
Macは標準装備だそうなので、やることなし。

【2011/04/21 00:45 】 | Android | 有り難いご意見(0) | トラックバック()
<<前ページ | ホーム |