- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个位于 android-design(23.4.0) 底页中的布局。我为底页内容设置的内容 View 有一个“下注”按钮和一个“接受更改” View 。它应该看起来像这样:
当价格发生变化时,用户必须接受更改 - 单击接受按钮会再次显示下注按钮。
问题是 BottomSheet 对话框由于某种原因没有正确初始化 - 开始时接受更改 View (处于状态 visibility==gone
)没有显示,我得到下面的结果。如果我单击其中一个编辑文本以显示键盘,那么当设置 placeBet 和 AcceptChangesView 的可见性时,似乎可以正确初始化它并且布局可以正确更新。但如果键盘尚未显示 - 不会发生布局更改并且 View 的布局数据未更改。自动显示和隐藏键盘似乎不起作用,我必须手动触摸编辑文本。我什至在所有不会更新的 View 上调用 forceLayout - 但即使这样也不会调用布局(请参阅下面的日志)
AcceptChangesView
中,布局属性(mTop、mLeft、mBottom、mRight)都显示为 0。测量的属性(getMeasuredWidth()、getMeasuredHeight())是正确的。ViewTreeObserver().addOnGlobalLayoutListener
并且 StraightBetDialogView.getMeasuredHeight() 高度正确,对话框高度也不会改变。 我如何模仿 Android 触摸系统/键盘所做的任何事情来正确初始化此对话框并正确处理 View 布局?
代码:
package com.gtech.liquidsportsbook.ui.dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.support.design.widget.BottomSheetBehavior;
import android.support.design.widget.BottomSheetDialog;
import android.util.Log;
import android.view.ViewTreeObserver;
import android.widget.FrameLayout;
import StraightBetDialogView;
/**
* Created by robert on 25/04/16.
*/
public class StraightBetDialog implements ViewTreeObserver.OnGlobalLayoutListener, DialogInterface.OnShowListener, StraightBetView.LayoutListener {
private final BottomSheetDialog dialog;
private final StraightBetView dialogView;
private final DialogInterface.OnDismissListener onDismissListener = new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(final DialogInterface dialog) {
dialogView.getViewTreeObserver().removeOnGlobalLayoutListener(StraightBetDialog.this);
ViewServer.get(getDialogView().getContext()).removeWindow(dialogView);
if (dialogView.getListener() != null) {
dialogView.getListener().onCancel();
}
}
};
public StraightBetDialog(final Context c) {
dialogView = new StraightBetView(c);
dialog = new BottomSheetDialog(c);
dialog.setContentView(dialogView);
dialog.setOnDismissListener(onDismissListener);
dialog.setCancelable(true);
dialog.setOnShowListener(this);
dialogView.getViewTreeObserver().addOnGlobalLayoutListener(this);
dialogView.setLayoutListener(this);
ViewServer.get(c).addWindow(dialogView, StraightBetView.class.getSimpleName());
}
public StraightBetView getDialogView() {
return dialogView;
}
public BottomSheetDialog getDialog() {
return dialog;
}
@Override
public void onGlobalLayout() {
adjustHeight();
}
public void adjustHeight() {
final FrameLayout bottomSheetFrameLayout = (FrameLayout) dialog.getWindow().findViewById(R.id.design_bottom_sheet);
// bottomSheetFrameLayout.getLayoutParams().height = ViewGroup.LayoutParams.WRAP_CONTENT;
// bottomSheetFrameLayout.forceLayout();
dialogView.invalidate();
final BottomSheetBehavior<FrameLayout> dialogBehaviour = BottomSheetBehavior.from(bottomSheetFrameLayout);
dialogBehaviour.setPeekHeight(dialogView.getMeasuredHeight());
dialogBehaviour.setState(BottomSheetBehavior.STATE_EXPANDED);
Log.d(getClass().getSimpleName(), "adjustHeight(): " + dialogView.getMeasuredHeight(), new Exception());
}
@Override
public void onShow(final DialogInterface dialog) {
if (dialogView.getParameters() != null) {
dialogView.getParameters().setHasChanges(false);
adjustHeight();
}
}
@Override
public void onLayout() {
adjustHeight();
}
}
相关布局xml如下:底部容器包含acceptChangesView和placeBetButton。
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/botttomContainer"
>
<com.gtech.liquidsportsbook.ui.views.AcceptChangesView
android:id="@+id/straightBetAcceptChanges"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"
app:listener="@{listener}"
/>
<Button
android:id="@+id/placeBetButton"
style="@style/style_mgm_button_betting"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:enabled="@{viewModel.placeBetEnabled}"
android:text="@string/placeBet"
android:onClick="@{listener.onPlaceBetClick}"
/>
</FrameLayout>
这里是 cumstom View 代码(我对 forceLayout 进行了一些不同的尝试 - 但没有一个真正起作用)。最初,viewModel 只是通过数据绑定(bind)根据 hasChanges 属性设置可见性。
public class StraightBetView extends FrameLayout {
private StraightBetViewModel viewModel;
private ViewStraightBetBinding binding;
private AmountListener amountListener;
private Listener listener;
private LayoutListener layoutListener;
@Inject
protected BettingUtils bettingUtils;
public interface AmountListener {
void onRiskChanged(final BigDecimal bigDecimal);
void onToWinChanged(final BigDecimal bigDecimal);
void onUnfocus(AmountInputEditText v);
}
public interface Listener extends AcceptChangesView.Listener {
void onPlaceBetClick(View v);
void onCancel();
}
public interface LayoutListener {
void onLayout();
}
private final AmountInputEditText.OnUnfocusListener editTextUnfocusListener = new AmountInputEditText.OnUnfocusListener() {
@Override
public void onUnfocus(final AmountInputEditText view) {
if (!binding.riskEditText.hasFocus() && !binding.toWinEditText.hasFocus()) {
UIUtils.closeKeyBoard(view);
} else {
UIUtils.showKeyBoard(view);
}
if (amountListener != null) {
amountListener.onUnfocus(view);
}
}
};
private final android.databinding.Observable.OnPropertyChangedCallback propertyChangedCallback = new android.databinding.Observable.OnPropertyChangedCallback() {
@Override
public void onPropertyChanged(final android.databinding.Observable observable, final int i) {
if (i == BR.hasChanges) {
setAcceptChangesState();
}
}
};
public StraightBetView(final Context context) {
super(context);
init(context);
}
public StraightBetView(final Context context, final AttributeSet attrs) {
super(context, attrs);
init(context);
}
public StraightBetView(final Context context, final AttributeSet attrs, final int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(context);
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public StraightBetView(final Context context, final AttributeSet attrs, final int defStyleAttr, final int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
init(context);
}
private void init(final Context context) {
MGMApplicationComponent.Injector.getComponent(context).inject(this);
final LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
binding = ViewStraightBetBinding.inflate(layoutInflater, this, true);
setId(R.id.straightBetContainer);
//setOrientation(VERTICAL);
binding.toWinEditText.setOnUnfocusListener(editTextUnfocusListener);
binding.riskEditText.setOnUnfocusListener(editTextUnfocusListener);
setAcceptChangesState();
}
private void updateView() {
binding.setViewModel(viewModel);
}
public StraightBetViewModel getParameters() {
return viewModel;
}
public void setParameters(final StraightBetViewModel parameters) {
if (viewModel != null) {
viewModel.removeOnPropertyChangedCallback(propertyChangedCallback);
}
this.viewModel = parameters;
viewModel.addOnPropertyChangedCallback(propertyChangedCallback);
//setAcceptChangesState();
updateView();
}
public AmountListener getAmountListener() {
return amountListener;
}
public void setAmountListener(final AmountListener amountListener) {
this.amountListener = amountListener;
binding.setAmountListener(amountListener);
}
@BindingAdapter("bind:amountListener")
public static void setAmountListener(final StraightBetView view, final AmountListener amountListener) {
view.setAmountListener(amountListener);
}
public Listener getListener() {
return listener;
}
public void setListener(final Listener listener) {
this.listener = listener;
binding.setListener(listener);
}
@BindingAdapter("bind:listener")
public static void setListener(final StraightBetView view, final Listener listener) {
view.setListener(listener);
}
public void localeChanged() {
LocaleUiUtil.initEditTextLocale(binding.riskEditText);
LocaleUiUtil.initEditTextLocale(binding.toWinEditText);
}
public void setAcceptChangesState() {
if (viewModel != null) {
binding.placeBetButton.setVisibility(!viewModel.isHasChanges() ? VISIBLE : GONE);
binding.straightBetAcceptChanges.setVisibility(viewModel.isHasChanges() ? VISIBLE : GONE);
}
binding.straightBetAcceptChanges.measure(MeasureSpec.makeMeasureSpec(getMeasuredWidth(), MeasureSpec.AT_MOST), MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
binding.straightBetAcceptChanges.forceLayout();
binding.straightBetAcceptChanges.layout(0, binding.botttomContainer.getTop(), getMeasuredWidth(), binding.botttomContainer.getTop() + binding.straightBetAcceptChanges.getMeasuredHeight());
binding.botttomContainer.measure(MeasureSpec.makeMeasureSpec(getMeasuredWidth(), MeasureSpec.AT_MOST), MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
binding.botttomContainer.forceLayout();
measure(MeasureSpec.makeMeasureSpec(getMeasuredWidth(), MeasureSpec.AT_MOST), MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
forceLayout();
if (layoutListener != null) {
layoutListener.onLayout();
}
}
public void setLayoutListener(final LayoutListener layoutListener) {
this.layoutListener = layoutListener;
}
}
显示对话框的代码非常简单:
public void showStraightBetDialog(final StraightBetDialogParameters straightBetParams, final Event event) {
straightBetDialog = new StraightBetDialog(getActivity());
getPresenter().createStraightBetViewModel(getActivity(), straightBetParams, event);
straightBetDialog.getDialogView().setParameters(getPresenter().getStraightBetViewModel());
straightBetDialog.getDialogView().setListener(this);
straightBetDialog.getDialogView().setAmountListener(getPresenter());
straightBetDialog.getDialog().show();
}
感谢任何帮助 - 如果我可以添加更多信息,请在评论中告诉我。
更新:此日志显示在触摸 View 之前未调用 onLayout。
06-01 12:08:28.221 28768-28768/com.app.dev D/StraightBetView: onMeasure : mw:0 mh:1593
06-01 12:08:28.271 28768-28768/com.app.dev D/StraightBetView: onAttachedToWindow:
06-01 12:08:28.271 28768-28768/com.app.dev D/StraightBetView.AcceptChangesView: onAttachedToWindow:
06-01 12:08:28.281 28768-28768/com.app.dev D/StraightBetView: onMeasure : mw:1440 mh:1008
06-01 12:08:28.331 28768-28768/com.app.dev D/StraightBetView: onMeasure : mw:1440 mh:1008
06-01 12:08:28.331 28768-28768/com.app.dev D/StraightBetView: onLayout : true left:0 top:0 right:1440 bottom:1008
06-01 12:08:28.331 28768-28768/com.app.dev D/StraightBetDialog: adjustHeight(): 1008
06-01 12:08:28.361 28768-28768/com.app.dev D/StraightBetDialog: adjustHeight(): 1008
06-01 12:08:28.361 28768-28768/com.app.dev D/StraightBetView: onMeasure : mw:1440 mh:1008
06-01 12:08:28.361 28768-28768/com.app.dev D/StraightBetDialog: adjustHeight(): 1008
06-01 12:08:28.391 28768-28768/com.app.dev D/StraightBetView: onMeasure : mw:1440 mh:1008
06-01 12:08:28.391 28768-28768/com.app.dev D/StraightBetDialog: adjustHeight(): 1008
<!—- price changed should show accept changes but onLayout is NOT called (onMeasuere is) -—>
06-01 12:08:55.201 28768-28768/com.app.dev D/StraightBetView.AcceptChangesView: onMeasure : mw:1440 mh:636
06-01 12:08:55.201 28768-28768/com.app.dev D/StraightBetView.AcceptChangesView: onMeasure : mw:1440 mh:636
06-01 12:08:55.221 28768-28768/com.app.dev D/StraightBetView.AcceptChangesView: onMeasure : mw:1440 mh:636
06-01 12:08:55.231 28768-28768/com.app.dev D/StraightBetView.AcceptChangesView: onMeasure : mw:1440 mh:636
06-01 12:08:55.231 28768-28768/com.app.dev D/StraightBetView: onMeasure : mw:1440 mh:1372
06-01 12:08:55.231 28768-28768/com.app.dev D/StraightBetDialog: adjustHeight(): 1372
<!—- ANOTHER CHNAGE (again onLayout is not called)-—>
06-01 12:10:57.141 28768-28768/com.app.dev D/StraightBetView.AcceptChangesView: onMeasure : mw:1440 mh:636
06-01 12:10:57.151 28768-28768/com.app.dev D/StraightBetView.AcceptChangesView: onMeasure : mw:1440 mh:636
06-01 12:10:57.161 28768-28768/com.app.dev D/StraightBetView.AcceptChangesView: onMeasure : mw:1440 mh:636
06-01 12:10:57.171 28768-28768/com.app.dev D/StraightBetView.AcceptChangesView: onMeasure : mw:1440 mh:636
06-01 12:10:57.171 28768-28768/com.app.dev D/StraightBetView: onMeasure : mw:1440 mh:1372
06-01 12:10:57.171 28768-28768/com.app.dev D/StraightBetDialog: adjustHeight(): 1372
<!—- CLOSED -—>
06-01 12:11:52.091 28768-28768/com.app.dev D/StraightBetView.AcceptChangesView: onDetachedFromWindow:
06-01 12:11:52.091 28768-28768/com.app.dev D/StraightBetView: onDetachedFromWindow:
<!—- SHOW AGAIN -—>
06-01 12:12:18.091 28768-28768/com.app.dev D/StraightBetView: onMeasure : mw:0 mh:1593
06-01 12:12:18.161 28768-28768/com.app.dev D/StraightBetView: onAttachedToWindow:
06-01 12:12:18.161 28768-28768/com.app.dev D/StraightBetView.AcceptChangesView: onAttachedToWindow:
06-01 12:12:18.171 28768-28768/com.app.dev D/StraightBetView: onMeasure : mw:1440 mh:1008
06-01 12:12:18.241 28768-28768/com.app.dev D/StraightBetView: onMeasure : mw:1440 mh:1008
06-01 12:12:18.241 28768-28768/com.app.dev D/StraightBetView: onLayout : true left:0 top:0 right:1440 bottom:1008
06-01 12:12:18.241 28768-28768/com.app.dev D/StraightBetDialog: adjustHeight(): 1008
06-01 12:12:18.261 28768-28768/com.app.dev D/StraightBetDialog: adjustHeight(): 1008
06-01 12:12:18.261 28768-28768/com.app.dev D/StraightBetView: onMeasure : mw:1440 mh:1008
06-01 12:12:18.261 28768-28768/com.app.dev D/StraightBetDialog: adjustHeight(): 1008
06-01 12:12:18.291 28768-28768/com.app.dev D/StraightBetView: onMeasure : mw:1440 mh:1008
06-01 12:12:18.291 28768-28768/com.app.dev D/StraightBetDialog: adjustHeight(): 1008
<!—- TOUCH -—>
06-01 12:12:46.391 28768-28768/com.app.dev D/StraightBetView: onMeasure : mw:1440 mh:1008
06-01 12:12:46.401 28768-28768/com.app.dev D/StraightBetDialog: adjustHeight(): 1008
<!—- CLOSE KEYBOARD -—>
06-01 12:13:49.711 28768-28768/com.app.dev D/StraightBetView: onMeasure : mw:1440 mh:1008
06-01 12:13:49.721 28768-28768/com.app.dev D/StraightBetView: onLayout : false left:0 top:0 right:1440 bottom:1008
06-01 12:13:49.721 28768-28768/com.app.dev D/StraightBetDialog: adjustHeight(): 1008
<!—- price changed should show accept changes (since the view was touched onLayout IS called and it displays correctly) -—>
06-01 12:14:48.461 28768-28768/com.app.dev D/StraightBetView.AcceptChangesView: onMeasure : mw:1440 mh:636
06-01 12:14:48.461 28768-28768/com.app.dev D/StraightBetView.AcceptChangesView: onMeasure : mw:1440 mh:636
06-01 12:14:48.471 28768-28768/com.app.dev D/StraightBetView.AcceptChangesView: onMeasure : mw:1440 mh:636
06-01 12:14:48.481 28768-28768/com.app.dev D/StraightBetView.AcceptChangesView: onMeasure : mw:1440 mh:636
06-01 12:14:48.481 28768-28768/com.app.dev D/StraightBetView: onMeasure : mw:1440 mh:1372
06-01 12:14:48.481 28768-28768/com.app.dev D/StraightBetDialog: adjustHeight(): 1372
06-01 12:14:48.481 28768-28768/com.app.dev D/StraightBetView.AcceptChangesView: onMeasure : mw:1440 mh:636
06-01 12:14:48.481 28768-28768/com.app.dev D/StraightBetView: onMeasure : mw:1440 mh:1372
06-01 12:14:48.491 28768-28768/com.app.dev D/StraightBetView.AcceptChangesView: onLayout : true left:0 top:0 right:1440 bottom:636
06-01 12:14:48.491 28768-28768/com.app.dev D/StraightBetView: onLayout : true left:0 top:0 right:1440 bottom:1372
06-01 12:14:48.491 28768-28768/com.app.dev D/StraightBetDialog: adjustHeight(): 1372
最佳答案
我遇到过类似的问题。如果您想以展开状态开始,请扩展 BottomSheetBehavior 并添加此方法。
public void setInitialState(int state) {
try {
Field field2 = BottomSheetBehavior.class.getDeclaredField("mState");
field2.setAccessible(true);
field2.set(this, state);
} catch (Exception e) {
Log.e("REFLECTION", e.getMessage());
}
在
之后立即调用此方法final BottomSheetBehavior<FrameLayout> dialogBehaviour = BottomSheetBehavior.from(bottomSheetFrameLayout);
我一直在为类似的问题而苦苦挣扎。这个问题的根源是你不能在 View 布局之前将状态设置为展开。这似乎是谷歌的疏忽,默认情况下不允许展开状态。初始状态标记为私有(private),因此必须使用反射来设置没有动画的状态。我希望这有帮助!我仍在与与此相关的其他问题作斗争,但对于您的用例,我相信这应该足够了。
如果这不起作用,请看这里: https://code.google.com/p/android/issues/detail?id=205226#c18此解决方案也可能有帮助
关于在触摸之前,Android 布局不会在底部表中更新/计算,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37551148/
我正在寻找一种使此打印 HTML 代码 fragment 向后兼容旧 Android 版本的简单方法: @TargetApi(Build.VERSION_CODES.KITKAT) private v
我在 GCC 终端 (centos linux) 中为 ATM 项目编译以下 c 和 .h 代码时收到以下错误。请帮忙,因为我是编程新手。 validate_acc.h #ifndef _VALIDA
在写关于 SO 的不同问题的答案时,我制作了这个片段: @import url('https://fonts.googleapis.com/css?family=Shadows+Into+Light'
试图弄清楚我应该如何在 my_div_class 之前放置一个 span 而不是替换所有它。现在它取代了 div,但我不想这样做。我假设它类似于 :before 但不知道如何使用它。 { va
我正在使用选择库 http://github.hubspot.com/select/和 noUiSlider https://refreshless.com/nouislider/ .我面临的问题如下
我是开发新手,独自工作。我正在使用 Xcode 和 git 版本控制。可能我没有适本地组织和做错事,但我通常决定做 promise 只是为了在我破坏一切之前做出安全点。在那一刻,我发现很难恰本地描述我
我想确保在同一个桶和键上读取和写入时,应该更新获取的值,也就是说,应该在对其进行写入操作之后获取它。我怎样才能做到这一点? 我想要的是,如果我更新一个键的值,如果我同时使用不同线程获取值,则更新同一个
我的问题与this有关问题,已经有了答案: yes, there is a happens-before relationship imposed between actionsof the thre
The before and after hook documentation on Relish仅显示 before(:suite) 在 before(:all) 之前调用。 我什么时候应该使用其中
我有 CSV 行,我想在其中检测所有内部双引号,没有文本限定符。这几乎可以正常工作,但我的正则表达式还可以检测双引号后的字符。 CSV 部分: "7580";"Lorem ipsum";"";"Lor
是否可以通过Youtube数据API检查广告是否可以与特定视频一起显示? 我了解contentDetails.licensedContent仅显示视频是否已上传至同一伙伴然后由其声明版权。由于第三者权
考虑一下用漂亮的彩色图表描述的“像素管道” https://developers.google.com/web/fundamentals/performance/rendering/ 我有一个元素(比
之前?
在 MVC3 中,我可以轻松地将 jQuery 脚本标签移动到页面底部“_Layout.vbhtml” 但是,在 ASP.NET MVC3 中,当您使用编辑器模板创建 Controller 时,脚手
悬停时内容被替换,但是当鼠标离开元素时我希望它变回来。我该怎么做? $('.img-wrap').hover(function(){ $(this).find('h4').text('Go
已关闭。这个问题是 not reproducible or was caused by typos 。目前不接受答案。 这个问题是由拼写错误或无法再重现的问题引起的。虽然类似的问题可能是 on-top
已关闭。这个问题是 not reproducible or was caused by typos 。目前不接受答案。 这个问题是由拼写错误或无法再重现的问题引起的。虽然类似的问题可能是 on-top
已关闭。此问题不符合Stack Overflow guidelines 。目前不接受答案。 已关闭 9 年前。 有关您编写的代码问题的问题必须在问题本身中描述具体问题 - 并包含有效代码以重现该问题。
版本:qwt 6.0.1我尝试开发频谱的对数缩放。我使用简单的线条来启用缩放plotspectrum->setAxisScaleEngine(QwtPlot::yLeft, new QwtLog10S
我有两个相同的表,I_Subject 和 I_Temp_Subject,我想将 Temp_Subject 表复制到 Subject 表。 I_Temp_Subject 由简单用户使用,I_Subjec
我的印象是第一次绘制发生在触发 DOMContentLoaded 事件之后。特别是,因为我认为为了让第一次绘制发生,需要渲染树,它依赖于 DOM 构造。另外,我知道 DOM 构造完成时会触发 DOMC
我是一名优秀的程序员,十分优秀!