2010年9月23日木曜日

Android 次へ・戻るボタンを作る

Button には上下左右に画像を配置することができます。
これを使うと、こんな感じの「次へボタン」や「戻るボタン」
が作れます。



次の attribute を指定します。

 android:drawableLeft="@drawable/icn_left"
 android:drawableRight="@drawable/icn_right"
 android:drawableTop="@drawable/icn_top"
 android:drawableBottom="@drawable/icn_bottom" 


いろいろ並べてみました。



drawable の場所は縁から一定で、width が変わると文字との距離が変わる。
padding を設定すると、drawable と縁との距離が変わる。

文字と drawable の間を設定することはできないみたい。。。うーむ。
android:drawablePadding を使ってできました!
kuriyama さんありがとうございます~。

 android:drawablePadding="10dip"

のように使います。



 
xml はこちら
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:orientation="vertical"  
  4.     android:layout_width="fill_parent"  
  5.     android:layout_height="fill_parent"  
  6.     >  
  7.     <Button  
  8.         android:layout_width="wrap_content"  
  9.         android:layout_height="wrap_content"  
  10.         android:text="Button"  
  11.         android:drawableLeft="@drawable/stat_sys_phone_call_forward"  
  12.         android:drawableRight="@drawable/stat_sys_phone_call_bluetooth"  
  13.         android:drawableTop="@drawable/stat_sys_phone_call"  
  14.         android:drawableBottom="@drawable/stat_sys_phone_call_on_hold"  
  15.         />  
  16.   
  17.       
  18.     <TextView  
  19.         android:layout_width="wrap_content"   
  20.         android:layout_height="wrap_content"   
  21.         android:text'android:padding="20dip"'  
  22.         />  
  23.     <Button  
  24.         android:layout_width="wrap_content"  
  25.         android:layout_height="wrap_content"  
  26.         android:text="Button"  
  27.         android:drawableLeft="@drawable/stat_sys_phone_call_forward"  
  28.         android:drawableRight="@drawable/stat_sys_phone_call_bluetooth"  
  29.         android:drawableTop="@drawable/stat_sys_phone_call"  
  30.         android:drawableBottom="@drawable/stat_sys_phone_call_on_hold"  
  31.         android:padding="20dip"  
  32.         />  
  33.   
  34.   
  35.     <TextView  
  36.         android:layout_width="wrap_content"   
  37.         android:layout_height="wrap_content"   
  38.         android:text'android:layout_weight="1"'  
  39.         />  
  40.     <LinearLayout  
  41.         android:orientation="horizontal"  
  42.         android:layout_width="fill_parent"  
  43.         android:layout_height="wrap_content"  
  44.         >  
  45.         <Button  
  46.             android:layout_width="0dip"  
  47.             android:layout_height="wrap_content"  
  48.             android:layout_weight="1"  
  49.             android:drawableLeft="@drawable/stat_sys_phone_call_forward"  
  50.             android:text="Button"  
  51.             />  
  52.       
  53.         <Button  
  54.             android:layout_width="0dip"  
  55.             android:layout_height="wrap_content"  
  56.             android:layout_weight="1"  
  57.             android:drawableRight="@drawable/stat_sys_phone_call_bluetooth"  
  58.             android:text="Button"  
  59.             />       
  60.     </LinearLayout>  
  61.   
  62.   
  63.     <TextView  
  64.         android:layout_width="wrap_content"   
  65.         android:layout_height="wrap_content"   
  66.         android:text'android:layout_width="wrap_content"'  
  67.         />  
  68.     <LinearLayout  
  69.         android:orientation="horizontal"  
  70.         android:layout_width="fill_parent"  
  71.         android:layout_height="wrap_content"  
  72.         >       
  73.         <Button  
  74.             android:layout_width="wrap_content"  
  75.             android:layout_height="wrap_content"  
  76.             android:drawableLeft="@drawable/stat_sys_phone_call_forward"  
  77.             android:text="Button"  
  78.             />  
  79.       
  80.         <Button  
  81.             android:layout_width="wrap_content"  
  82.             android:layout_height="wrap_content"  
  83.             android:drawableRight="@drawable/stat_sys_phone_call_bluetooth"  
  84.             android:text="Button"  
  85.             />              
  86.     </LinearLayout>  
  87.   
  88.   
  89.     <TextView  
  90.         android:layout_width="wrap_content"   
  91.         android:layout_height="wrap_content"   
  92.         android:text'android:layout_width="150dip"'  
  93.      />  
  94.     <LinearLayout  
  95.         android:orientation="horizontal"  
  96.         android:layout_width="fill_parent"  
  97.         android:layout_height="wrap_content"  
  98.         >  
  99.         <Button  
  100.             android:layout_width="150dip"  
  101.             android:layout_height="wrap_content"  
  102.             android:drawableLeft="@drawable/stat_sys_phone_call_forward"  
  103.             android:text="Button"  
  104.             />  
  105.       
  106.         <Button  
  107.             android:layout_width="150dip"  
  108.             android:layout_height="wrap_content"  
  109.             android:drawableRight="@drawable/stat_sys_phone_call_bluetooth"  
  110.             android:text="Button"  
  111.             />       
  112.     </LinearLayout>  
  113. </LinearLayout>  

3 件のコメント:

  1. >文字と drawable の間を設定することはできないみたい
    android:drawablePaddingでできると思います♪

    返信削除
  2. 情報ありがとうございます!

    返信削除
  3. eipapaと申します
    私が入手したiPhone 4にそっくりなAndroid端末にはハード的な「BACKキー」や「NEXTキー」がありません上記のようなアプリやウィジットはないでしょうか?

    返信削除