2010年9月19日日曜日

Android layout_weight チップス

とあるアプリのソースを見ていたら、こういう指定方法をしていたので

 android:layout_width="0dip"
 android:layout_height="wrap_content"
 android:layout_weight="1"

めもめも。width が 0 !

こんな感じで使う

  1. <LinearLayout  
  2.     android:orientation="horizontal"  
  3.     android:layout_width="fill_parent"  
  4.     android:layout_height="wrap_content"  
  5.     >       
  6.     <Button  
  7.         android:layout_width="0dip"  
  8.         android:layout_height="wrap_content"  
  9.         android:layout_weight="1"  
  10.         android:text="Left"  
  11.         android:layout_marginTop="5dip"  
  12.         />  
  13.       
  14.     <Button  
  15.         android:layout_width="0dip"  
  16.         android:layout_height="wrap_content"  
  17.         android:layout_weight="1"  
  18.         android:text="Right"  
  19.         android:layout_marginTop="5dip"  
  20.  />  
  21. </LinearLayout>  


layout_weight を使うケースとしては

 android:layout_width="fill_parent"
 android:layout_height="wrap_content"
 android:layout_weight="1"

をよく使ってたので、試しに並べてみました。



、、、同じですね。

fill_parent にしたくない場合
(そういえば API 8 からは match_parent が推奨なんだった)
にはいいのかもね



 

0 件のコメント:

コメントを投稿