目次へ
| LinearLayoutのweightを使うと全体の大きさに合わせて重みづけを指定することができます |
■■■■layoutのxmlでweightを指定する■■■■
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout ①
android:id="@+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/back" />
<EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" > ②
<requestFocus />
</EditText>
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="★" />
</LinearLayout>
<WebView
android:id="@+id/webView1"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
①で、orientationを指定していないのでこのLinearLayoutはhorizontalが指定されていることになり、ボタンとエディットテキストとボタンの3つのViewが横に並びます。
weightを指定しているのはエディットテキストだけなので( ② )、ボタンを2つ作った残りのサイズはすべてエディットテキストとなります。
もし、3つともweightを1,1,1と指定すれば、同じ大きさになり、
また、weightを1,2,1と指定すれば、2と指定されたものだけが2倍の大きさになります。
にほんブログ村
0 件のコメント:
コメントを投稿