2011-11-28 49 views
4

我創建我的自定義烤麪包主要是因爲我把它放在網格視圖上,需要對它的寬度進行一些控制。但我真的很喜歡標準烤麪包上的淺藍色光環,並希望能夠回到原來的位置(或者至少讓我的定製烤麪包有點類似於默認的烤麪包)。如何在我的烤麪包中烤麪包的淺藍色暈圈?

什麼是簡單的/優雅的方式來實現這一目標?

我創造了這個佈局定製舉杯:

<LinearLayout 
     android:id="@+id/toast_layout_root" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:orientation="horizontal" android:padding="10dp"> 
     <ImageView android:id="@+id/toast_layout_image" 
      android:layout_width="wrap_content" android:layout_height="wrap_content" 
      android:src="@drawable/icon" android:layout_marginRight="10dp"> 
     </ImageView> 
     <TextView android:layout_width="wrap_content" 
      android:layout_height="wrap_content" android:id="@+id/toast_layout_text"   
      android:textColor="#FFF" android:textAppearance="?android:attr/textAppearanceLarge"> 
     </TextView> 
    </LinearLayout> 

並調用它這種方式(如Android開發人員列出常見的方法文檔以及一對夫婦在網絡上的教程,唯一的區別是我有一個網格視圖工作,每個麪包被置於根據其網格貼磚的位置):

int location[] = new int[2]; 
view.getLocationOnScreen(location); 
LayoutInflater inflater = getLayoutInflater(); 
View toastLayout = inflater.inflate(R.layout.toast_layout,(ViewGroup)findViewById(R.id.toast_layout_root)); 
TextView textView = (TextView) toastLayout.findViewById(R.id.toast_layout_text); 
textView.setText("This tile does not contain any valid data."); 
int toastWidth = cellWidth * 3/4; 
textView.setWidth(toastWidth - 64); // TODO picture size needs to be correct 

Toast toast = new Toast(getApplicationContext()); 
toast.setView(toastLayout); 
toast.setDuration(Toast.LENGTH_SHORT); 
toast.setGravity(Gravity.TOP|Gravity.LEFT, location[0]+((cellWidth-toastWidth)/2),location[1]+cellHeight-100);    
toast.show(); 

這看起來很乾淨,但在默認土司完全不同..

回答

4

你敬酒信息應用此佈局:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@+id/toast_layout_root" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:padding="35dp" 
     android:orientation="horizontal" 
     android:background="@android:drawable/dialog_holo_dark_frame" > 
     <ImageView android:id="@+id/toast_layout_image" 
      android:layout_width="wrap_content" android:layout_height="wrap_content" 
      android:src="@drawable/appicon" android:layout_marginRight="10dp"> 
     </ImageView> 
     <TextView android:layout_width="wrap_content" 
      android:layout_height="wrap_content" android:id="@+id/toast_layout_text"   
      android:textColor="#FFF" android:textAppearance="?android:attr/textAppearanceLarge"> 
     </TextView> 
    </LinearLayout> 

我沒有發現有什麼cellWidth和cellHeight,所以儘量用填充實驗,如果它不適合
編輯:哦,我申請黑暗的主題,請嘗試使用光線代替。

+0

正確的參考背景出來是「@android:繪製/ toast_frame」(有所有的Android可繪製一張好名單這裏:http://androiddrawableexplorer.appspot.com/) – EtienneSky