忍者ブログ
  • 2024.04
  • 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
  • 31
  • 2024.06
[PR]
×

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

【2024/05/16 22:35 】 |
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など)の整理

プログラム中からのセット方法
PR
【2014/08/28 19:33 】 | Android | 有り難いご意見(0)
<<LinearLayout | ホーム | gitコマンド>>
有り難いご意見
貴重なご意見の投稿














<<前ページ | ホーム | 次ページ>>