今天我把我的吐司改成了面包丁。但我有这些问题:
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);
我相信我错过了一些东西。希望已经有正确的方法来做这些.
不鼓励在库本身内进行更改,因为它可能会产生仅在您的 Crouton 版本中出现的问题。
您可以通过Configuration.Builder.setInAnimation(...)
和.setOutAnimation(...)
更改动画。
Configuration
可以重复使用,不必每次要显示Crouton
时都创建。同样适用于您的View
。它不必每次都充气。
关于面包丁的重复显示:此行为不是有意的。上面的代码看起来应该显示一个带有info
文本集的 Crouton。如果您的info
文本在 Cuctons 显示期间发生了更改,则可能是库中的错误。如果是这种情况,请随时报告。