Home > Android > [Android] レイアウトでViewを両端に配置する方法

[Android] レイアウトでViewを両端に配置する方法

レイアウトでViewを両端に配置する方法はいくつか存在しますが、ここで紹介する方法が一番シンプルで分かりやすい気がします。

方法はコードを見てもらえば一目瞭然ですが、配置する2つのViewの真ん中に「android:layout_weight」を”1″にしたViewを埋め込むだけです。
 

1<?xml version="1.0" encoding="utf-8"?>
2<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3    android:layout_width="match_parent"
4    android:layout_height="match_parent"
5    android:orientation="vertical" >
6 
7    <LinearLayout
8        android:layout_width="wrap_content"
9        android:layout_height="wrap_content"
10        android:layout_margin="10dp">
11         
12        <TextView
13            android:layout_width="wrap_content"
14            android:layout_height="wrap_content"
15            android:text="左" />
16 
17        <View
18            android:layout_width="wrap_content"
19            android:layout_height="wrap_content"
20            android:layout_weight="1" />
21         
22        <TextView
23            android:layout_width="wrap_content"
24            android:layout_height="wrap_content"
25            android:text="右" />
26 
27    </LinearLayout>
28 
29</LinearLayout>

 
こんな感じで表示されます。

 
 

関連があると思われる記事:

このエントリーをはてなブックマークに追加
はてなブックマーク - [Android] レイアウトでViewを両端に配置する方法
Facebook にシェア
[`google_buzz` not found]
[`yahoo` not found]
[`livedoor` not found]
[`friendfeed` not found]
[`tweetmeme` not found]
[`grow` not found]

Comments:0

Comment Form
Remember personal info

Trackbacks:0

Trackback URL for this entry
http://gacken.com/wp/program/android/1510/trackback/
Listed below are links to weblogs that reference
[Android] レイアウトでViewを両端に配置する方法 from ミライニトドケ

Home > Android > [Android] レイアウトでViewを両端に配置する方法

Search
Feeds
Meta
人気の記事

Return to page top