2011-11-28 64 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