Comments (24)
DialogFragment好在是有生命周期,DialogFragment内部也是Dialog。它提供有可以自定义Dialog的方法,用HappyBubble替换内部默认的就行了。
from happybubble.
原来可以这样。
from happybubble.
嗯,如果没有必要的话不必要弄的那么复杂哦
from happybubble.
重写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.
你可以写一个类继承BubbleDialog,在这个类里面想怎么操作都行。然后直接返回这个类的给这个方法就行了
from happybubble.
为什么会有要求setArguments呢?显示是这样显示的
mDialogFragment.show(getFragmentManager(), "DialogFragment");
from happybubble.
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.
我的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.
原来是这个意思!你可以试试这样。
通过提前调用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.
如果我这样调用的话
MyDialogFragment dialog=new MyDialogFragment();
dialog.setClickedView(view);
有一点不能保证的是
DialogFragment 里面的onCreateDialog 先执行
还是setClickedView先执行
万一onCreateDialog 里面先执行,mClickedView可能为空。
from happybubble.
这样写因该是没有问题的,因为onCreateDialog调用始终会在之后
from happybubble.
嗯,有一个潜在的问题是横竖屏切换后,mClickedView会为空,
我也很纠结这个问题。
from happybubble.
切换横竖屏的时候再相关的生命周期中重新初始化比如说在onStart()中进行初始化
from happybubble.
或者说在这里setClickedView,可以试试看
from happybubble.
确实可以这么做。
如果BubbleDialog 可以在dialog显示后,
提供方法,转移到其它任意view上显示箭头就好了
就更好了(=・ω・=)
from happybubble.
这个想法不错,因为我用的时候都是不同的dialog样式,没想到过这需求
from happybubble.
还需要你帮忙试一试,通过setClickedView就可以直接重新更新位置
happy-bubble-release.zip
from happybubble.
@xujiaji 好的,不过我这边有点下载不下来
from happybubble.
我这边已经出门了,要不你加我一下QQ吧!回去发给你。
QQ号:624719201
from happybubble.
@weituotian 你好!有试过有什么问题吗?
from happybubble.
@xujiaji 很棒,非常好用!我写了个demo。
from happybubble.
好的,那我晚上在上传上去。你这里面的测试代码可以让我拷贝进来吗?(≧▽≦)
from happybubble.
嗯,随便用。(⌒▽⌒)
from happybubble.
@weituotian 新版本以更新,可以直接引用了。并添加新方法“setRelativeOffset(int)”设置dialog相对于被点击view的偏移量
from happybubble.
Related Issues (20)
- 在安卓10上,弹窗会先在中间弹出,再偏移到指定位置显示。 HOT 1
- 能否支持设置边框? HOT 2
- 几个问题 HOT 4
- 如何给bubble添加图片背景 HOT 1
- Bubblelyout自带的padding如何去除
- 关于 bubblePadding HOT 1
- 很好用的气泡效果, 但是必须强制带箭头.. 能否可以不需要箭头? HOT 1
- 在view的正下方显示不适配。。。
- TextView自动换行了 HOT 20
- 初始化BubbleDialog,super(context)报错,java.lang.InstantiationException: java.lang.Class<com.android.internal.R$dimen> has no zero argument constructor HOT 5
- 请支持RTL布局 HOT 4
- BubbleLayout嵌套exoplayer,无法播放视频 HOT 21
- BubbleLayout高度超出手机屏幕直接不显示了 HOT 2
- App若未适配挖孔屏,会导致dialog位置偏移
- 气泡的Y轴位置有问题 HOT 1
- 1.2.5下载不了,1.2.4可以,是不是没上传 HOT 2
- 自定义 BubbleDialog的时候如何改变气泡和倒三角的颜色啊 HOT 1
- 关于箭头位置问题 HOT 3
- 箭头位置在列表中设置无效 HOT 11
- 依赖 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from happybubble.