2

今天我把我的吐司换成了面包块。但我有这些问题:

1)在中心显示烤面包片

2)每当我想显示新的Crouton时,它都会再次显示以前的Crouton,尽管以前的Crouton很久以前就隐藏了

我想知道是否有更好的方法来解决上述问题?因为我查看了样本和库但找不到“

目前我正在解决这些方法

活动布局:

<RelativeLayout 
    android:id="@+id/bigcontainer"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
    android:layout_height="match_parent"
    >





<FrameLayout 
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".DilmancSRActivity"
    tools:ignore="MergeRootFrame" />

     <RelativeLayout
    android:id="@+id/alternate_view_group"
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"   
    android:layout_centerInParent="true" 

    />
</RelativeLayout>

创建我的自定义 toast 视图并将其水平居中:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/toast_layout_root"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center_horizontal"
    >
<LinearLayout 
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/kdrw"
    android:orientation="horizontal"
    android:padding="8dp" >

    <ImageView
        android:layout_width="40dp"
        android:layout_height="40dp"
        android:layout_marginRight="8dp"
        android:contentDescription="@string/strnull"
        android:src="@drawable/logo" />

    <TextView
        android:id="@+id/toasttextView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:text="Large Text"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:textColor="#000000" />

</LinearLayout>

</LinearLayout>

显示油炸面包丁:

    LayoutInflater inflater = localdsr.getLayoutInflater();
                        View layout = inflater.inflate(R.layout.toast, null); 
                        TextView text = (TextView) layout.findViewById(R.id.toasttextView1);
                        text.setText(info);  
                        if (toast != null)
                            toast.cancel();

                        Configuration croutonConfiguration=new Configuration.Builder().setDuration(1500).build();


                    toast=Crouton.make(localdsr, layout ,R.id.alternate_view_group ,croutonConfiguration); 

                    toast.show();

为了解决第二个问题,我必须下载库源并使用它。.因为我不想首先使用动画,所以我禁用了动画

   //croutonView.startAnimation(crouton.getInAnimation());

删除使事物再次出现在内部的功能的问题 protected void removeCrouton(Crouton crouton)

  //sendMessageDelayed(crouton, Messages.DISPLAY_CROUTON, crouton.getOutAnimation().getDuration());
 //I changed it with below .plus removed crouton.getOutAnimation().getDuration() so it does not throw exception
sendMessage(crouton, Messages.DISPLAY_CROUTON);

我相信我错过了一些东西。希望已经有正确的方法来做这些。

4

1 回答 1

2

不鼓励在库本身内进行更改,因为它可能会产生仅出现在您的 Crouton 版本中的问题。

Configuration.Builder.setInAnimation(...)您可以通过和更改动画.setOutAnimation(...)

可以重复使用Configuration,不必在每次要显示Crouton. 这同样适用于您的View. 它不必每次都膨胀。

关于 Crouton 的重复显示:此行为不是有意的。上面的代码看起来应该显示带有info文本集的面包块。如果您的info文本在显示面包块期间发生了更改,则可能是库中的错误。如果是这种情况,请随时报告

于 2014-01-09T09:06:37.787 回答