Code Monkey home page Code Monkey logo

Comments (24)

xujiaji avatar xujiaji commented on June 2, 2024

DialogFragment好在是有生命周期,DialogFragment内部也是Dialog。它提供有可以自定义Dialog的方法,用HappyBubble替换内部默认的就行了。

from happybubble.

weituotian avatar weituotian commented on June 2, 2024

原来可以这样。

from happybubble.

xujiaji avatar xujiaji commented on June 2, 2024

嗯,如果没有必要的话不必要弄的那么复杂哦

from happybubble.

weituotian avatar weituotian commented on June 2, 2024

@xujiaji

重写dialogfragment时遇到一个问题

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        rootView = LayoutInflater.from(getActivity()).inflate(R.layout.dialog_timeline_item_more, null);
        mViewHolder = new ViewHolder(rootView);

        return new BubbleDialog(getActivity())
                .calBar(true)
                .setPosition(BubbleDialog.Position.TOP)
                .softShowUp()
                .autoPosition(true)
                .setThroughEvent(false, true)
                .addContentView(rootView);
    }

重写dialogfragment 的 onCreateDialog 这个方法

没法调用 BubbleDialog 的 setClickedView 方法去设置是从哪个view点击的?怎么办?

而且dialogfragment的初始化方法要求setArguments(bundle), bundle要求put实现了Parcelable的类,然后变复杂了。

from happybubble.

xujiaji avatar xujiaji commented on June 2, 2024

你可以写一个类继承BubbleDialog,在这个类里面想怎么操作都行。然后直接返回这个类的给这个方法就行了

from happybubble.

xujiaji avatar xujiaji commented on June 2, 2024

为什么会有要求setArguments呢?显示是这样显示的

mDialogFragment.show(getFragmentManager(), "DialogFragment");

from happybubble.

weituotian avatar weituotian commented on June 2, 2024
Bundle arguments = new Bundle();
       arguments.putString(KEY_LOADING_TEXT, loadingText);
       MyDialogFragment = new MyDialogFragment ();
       dialog.setArguments(arguments);

要把被点击的view 作为参数 传给 dialogfragment,

diafragment 初始化 BubbleDialog的时候可以getArguments(), 获得被点击的view,然后BubbleDialog可以显示在被点击的view的上方。

我就想传这么大一个view不太好吧

from happybubble.

weituotian avatar weituotian commented on June 2, 2024

我的Dialog继承DialogFragment ,内部是可以自由操作BubbleDialog的

public class MyDialogFragment extends DialogFragment {

   private Context mContext;
    private View rootView;
    private ViewHolder mViewHolder;
    private BubbleDialog bubbleDialog;

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        rootView = LayoutInflater.from(getActivity()).inflate(R.layout.dialog_timeline_item_more, null);
        mViewHolder = new ViewHolder(rootView);

        bubbleDialog = new BubbleDialog(getActivity())
                .calBar(true)
                .setPosition(BubbleDialog.Position.TOP)
                .softShowUp()
                .autoPosition(true)
                .setThroughEvent(false, true)
                .addContentView(rootView);
        return bubbleDialog;
    }

   private static class ViewHolder
    {
        Button btn13, btn14, btn15;
        public ViewHolder(View rootView)
        {
            btn13 = (Button) rootView.findViewById(R.id.button13);
            btn14 = (Button) rootView.findViewById(R.id.button14);
            btn15 = (Button) rootView.findViewById(R.id.button15);
        }
    }
}

from happybubble.

xujiaji avatar xujiaji commented on June 2, 2024

原来是这个意思!你可以试试这样。
通过提前调用setClickedView()方法把被点击的view放进去

public class MyDialogFragment extends DialogFragment {

   private Context mContext;
    private View rootView;
    private ViewHolder mViewHolder;
    private BubbleDialog bubbleDialog;
    private View mClickedView;//new code

   public void setClickedView(View clickView)//new code
   {
         mClickedView = clickView;
   }

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        rootView = LayoutInflater.from(getActivity()).inflate(R.layout.dialog_timeline_item_more, null);
        mViewHolder = new ViewHolder(rootView);

        bubbleDialog = new BubbleDialog(getActivity())
                .calBar(true)
                .setPosition(BubbleDialog.Position.TOP)
                .softShowUp()
                .autoPosition(true)
                .setClickedView(mClickedView)//new code
                .setThroughEvent(false, true)
                .addContentView(rootView);
        return bubbleDialog;
    }

   private static class ViewHolder
    {
        Button btn13, btn14, btn15;
        public ViewHolder(View rootView)
        {
            btn13 = (Button) rootView.findViewById(R.id.button13);
            btn14 = (Button) rootView.findViewById(R.id.button14);
            btn15 = (Button) rootView.findViewById(R.id.button15);
        }
    }
}

from happybubble.

weituotian avatar weituotian commented on June 2, 2024

如果我这样调用的话

MyDialogFragment dialog=new MyDialogFragment();
dialog.setClickedView(view);

有一点不能保证的是
DialogFragment 里面的onCreateDialog 先执行
还是setClickedView先执行

万一onCreateDialog 里面先执行,mClickedView可能为空。

from happybubble.

xujiaji avatar xujiaji commented on June 2, 2024

这样写因该是没有问题的,因为onCreateDialog调用始终会在之后

from happybubble.

weituotian avatar weituotian commented on June 2, 2024

嗯,有一个潜在的问题是横竖屏切换后,mClickedView会为空,
我也很纠结这个问题。

from happybubble.

xujiaji avatar xujiaji commented on June 2, 2024

切换横竖屏的时候再相关的生命周期中重新初始化比如说在onStart()中进行初始化

from happybubble.

xujiaji avatar xujiaji commented on June 2, 2024

或者说在这里setClickedView,可以试试看

from happybubble.

weituotian avatar weituotian commented on June 2, 2024

确实可以这么做。

如果BubbleDialog 可以在dialog显示后,
提供方法,转移到其它任意view上显示箭头就好了
就更好了(=・ω・=)

from happybubble.

xujiaji avatar xujiaji commented on June 2, 2024

这个想法不错,因为我用的时候都是不同的dialog样式,没想到过这需求

from happybubble.

xujiaji avatar xujiaji commented on June 2, 2024

还需要你帮忙试一试,通过setClickedView就可以直接重新更新位置
happy-bubble-release.zip

from happybubble.

weituotian avatar weituotian commented on June 2, 2024

@xujiaji 好的,不过我这边有点下载不下来

from happybubble.

xujiaji avatar xujiaji commented on June 2, 2024

我这边已经出门了,要不你加我一下QQ吧!回去发给你。
QQ号:624719201

from happybubble.

xujiaji avatar xujiaji commented on June 2, 2024

@weituotian 你好!有试过有什么问题吗?

from happybubble.

weituotian avatar weituotian commented on June 2, 2024

timeLangGuiTest.zip

@xujiaji 很棒,非常好用!我写了个demo。

from happybubble.

xujiaji avatar xujiaji commented on June 2, 2024

好的,那我晚上在上传上去。你这里面的测试代码可以让我拷贝进来吗?(≧▽≦)

from happybubble.

weituotian avatar weituotian commented on June 2, 2024

嗯,随便用。(⌒▽⌒)

from happybubble.

xujiaji avatar xujiaji commented on June 2, 2024

@weituotian 新版本以更新,可以直接引用了。并添加新方法“setRelativeOffset(int)”设置dialog相对于被点击view的偏移量

from happybubble.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.