简体   繁体   English

在Android中以编程方式更改线性布局高度

[英]change linear layout height programmatically in Android

I am trying to change the height of linear layout programmatically. 我试图以编程方式更改线性布局的高度。 When I use 我用的时候

ll.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));

I am getting exception: 我得到例外:

java.lang.ClassCastException: android.view.ViewGroup$LayoutParams java.lang.ClassCastException:android.view.ViewGroup $ LayoutParams

我得到了解决方案LinearLayout.LayoutParams

ll.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT));

My guess is you're importing a different LayoutParams. 我的猜测是你要导入一个不同的LayoutParams。 Try a fully qualified version: 尝试完全限定版本:

ll.setLayoutParams(new android.view.ViewGroup.LayoutParams(
    android.view.ViewGroup.LayoutParams.FILL_PARENT,
    android.view.ViewGroup.LayoutParams.WRAP_CONTENT
));

When you first include LayoutParams in your code and hit Cntrl+Shift+Enter to automatically import the required files, you are displayed a list of all the packages. 当您首次在代码中包含LayoutParams并按Cntrl + Shift + Enter以自动导入所需文件时,将显示所有包的列表。 Make sure you import the right package in your code. 确保在代码中导入正确的包。

import android.view.ViewGroup.LayoutParams;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM