首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Crouton中心定制视图及消失问题

Crouton中心定制视图及消失问题
EN

Stack Overflow用户
提问于 2014-01-08 14:32:29
回答 1查看 873关注 0票数 2

今天我把我的烤面包换成了Crouton。但我遇到了这样的问题:

1)在中心显示Crouton

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

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

目前我正在解决这些问题

活动布局:

代码语言:javascript
复制
<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>

创建我的自定义吐司视图并将其水平对齐:

代码语言:javascript
复制
<?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>

向Crouton展示:

代码语言:javascript
复制
    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();

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

代码语言:javascript
复制
   //croutonView.startAnimation(crouton.getInAnimation());

关于删除在 protected void removeCrouton(Crouton crouton)中再次出现的函数的问题

代码语言:javascript
复制
  //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);

我想我错过了什么。希望已经有正确的方法去做了。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-01-09 09:06:37

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

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

Configuration可以重用,不必每次显示Crouton时都要创建。对您的View也是有效的。它不需要每次都被膨胀。

关于Crouton的重复显示:此行为不是有意的。上面的代码看起来应该显示一个带有info文本集的Crouton。如果您的info文本在显示Croutons期间发生了更改,那么它可能是库中的一个bug。如果是这样的话,可以随意使用报告它

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20998473

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档