gpt4 book ai didi

java - 面包丁居中自定义 View 和消失的问题

转载 作者:行者123 更新时间:2023-11-30 09:13:32 27 4
gpt4 key购买 nike

今天我把我的 toast 换成了面包丁。但是我遇到了这些问题:

1)在中心显示面包丁

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

我想知道有没有更好的办法解决以上问题??因为我查看了示例和库但找不到“

目前我正在解决这些问题

Activity 布局:

<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 View 并将其水平居中:

<?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 文本集的面包丁。如果您的 info 文本在 Croutons 的显示期间发生了变化,则可能是库中的错误。如果是这样,请随时report it .

关于java - 面包丁居中自定义 View 和消失的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20998473/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com