草庐IT

getLayoutParams

全部标签

android - PopupWindow.getContentView().getLayoutParams() 在 Android Marshmallow 中返回一个不同的类

我有如下代码。....PopupWindowpopupWindow=newPopupWindow(someView);finalWindowManager.LayoutParamslayoutParams=(WindowManager.LayoutParams)popupWindow.getContentView().getLayoutParams();....问题popupWindow.getContentView().getLayoutParams正在返回不同的类,因为我的类型转换失败了在Marshamallow之前:android.View.WindowManager.Layou

android - view.getLayoutParams().width 不适用于牛轧糖

我已经编写了代码来动态设置View的高度和宽度view.getLayoutParams().width=120;view.getLayoutParams().height=120;它与以下nougat设备完美配合,但与nougat不兼容。它只是将高度和宽度设为0。牛轧糖更新后有什么变化吗?更新:不管怎样都行1)当我在设置高度和宽度后使用view.requestLayout()时2)view.setLayoutParams(newLinearLayout.LayoutParams(200,120));那么为什么它在不使用这2个选项的情况下在prenougat设备上工作?

android - getLayoutParams 返回空值?

我创建了一个扩展View的类:publicclassBoardViewextendsView{并且我在应用程序的main.xml文件中指定了BoardView的宽度和高度:我正在尝试从BoardView的构造函数调用的函数中获取宽度和高度。这是我正在做的:ViewGroup.LayoutParamsp=this.getLayoutParams();inth=p.height;但是getLayoutParams总是返回null。知道为什么这不起作用吗? 最佳答案 将View添加到其父View后,布局参数可用。尝试将代码从View构造函

java - 为什么 LinearLayout instance.getLayoutParams 看起来有一个错误的类?

如果我声明LinearLayoutlinearLayout并查看linearLayout.getLayoutParams(),它会给我ViewGroup.LayoutParams,而不是LinearLayout.LayoutParams.所以我必须使用重复(因此不好)的样式构造:intlm=((LinearLayout.LayoutParams)linearLayout.getLayoutParams()).leftMargin?例如,如果我想达到利润率,我真的必须使用它吗?是我对Android还是Java,或者两者都有误解,还是别的? 最佳答案

android - ImageView getLayoutParams() 返回 null

我正在用这个简单的方法以编程方式创建一个小部件privateImageViewgetModuleIconView(Modulemodule){ImageViewview=newImageView(context);view.setImageResource(module.getIconResId());view.getLayoutParams().height=50;//NullPointerExceptionreturnview;}我得到NullPointer异常,因为getLayoutParams返回null。这是为什么呢? 最佳答案
12