小编Mic*_*aël的帖子

使用零内在大小的自定义视图设置AlertDialog的高度

上下文

一个简单的缝合任务,我想设置AlertDialog包含自定义视图的高度.通过关于这个主题的十几个SO问题,我想出了12个!可能的答案.在尝试了所有这些(每秒尝试15年)之后,似乎在屏幕上敲击我的头也有同样的效果:没有.我想这样做的原因是我的自定义视图没有内在的维度,它只是跨越给定的空间.


目标

这里的问题是指软目标,但我很乐意接受这个目标的答案!

软目标: 创建AlertDialog一个自定义空ViewGroup(或包含,例如,一个ImageView),并将对话框的宽度和高度设置为特定值.

硬目标:当以编程方式给出对话框的尺寸时,创建一个尽可能占用空间AlertDialog方形形状.


我的尝试,凝聚

Java的:

View layout = getLayoutInflater ().inflate (R.layout.alerttest, null);

AlertDialog alert = new AlertDialog.Builder (this)
    .setPositiveButton(R.string.alert_dialog_ok, null)
    .setTitle ("Don't cry, will you?")
    // .setView (layout) may be done here.
    .create();

alert.show ();

// alert.setView (layout) here, or before .show, or I can use the doc's:

FrameLayout fl = (FrameLayout) alert.findViewById (android.R.id.custom);
fl.addView (layout, new LayoutParams (500, 500)); // Arbitrary dimensions …
Run Code Online (Sandbox Code Playgroud)

android android-layout android-alertdialog

6
推荐指数
0
解决办法
970
查看次数

Partial template deduction in constructors

Problem: I'm often in a situation where some types can be deduced from the constructor's arguments, but not all:

template <typename Res, typename Arg>
struct adder {
    adder (Arg a1, Arg a2) : a1 {a1}, a2 {a2} {}
    void compute () { res = a1 + a2; }
    Res result () { return res; }

    Arg a1, a2;
    Res res;
};
Run Code Online (Sandbox Code Playgroud)

If I'm using int arguments and want to specify unsigned as result type, I would like to write something …

c++ templates constructor c++17

4
推荐指数
1
解决办法
46
查看次数

GCC:溢出的未定义行为是否应该保持逻辑一致性?

以下代码在我的系统上产生奇怪的东西:

#include <stdio.h>

void f (int x) {
  int y = x + x;
  int v = !y;
  if (x == (1 << 31))
    printf ("y: %d, !y: %d\n", y, !y);
}

int main () {
  f (1 << 31);
  return 0;
}
Run Code Online (Sandbox Code Playgroud)

编译-O1,这打印y: 0, !y: 0.

现在,除了删除int vif行产生预期结果的令人费解的事实之外,我对溢出转换为逻辑不一致的未定义行为感到不舒服。

这应该被认为是一个错误,还是 GCC 团队的理念是,一个意外的行为可以级联成逻辑矛盾?

c gcc overflow undefined-behavior integer-arithmetic

0
推荐指数
1
解决办法
95
查看次数