- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我整个上午都在为 Android 上的这个问题苦苦思索。我有一个 ListView,我需要为其计算高度。
我正在使用这段代码:
int totalHeight = 0;
for (int size = 0; size < myListAdapter.getCount(); size++) {
View listItem = myListAdapter.getView(size, null, myListView);
listItem.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
totalHeight += listItem.getMeasuredHeight();
}
然而,我在这里找到的 - 列表项的特定布局的返回值小于真实值(对于其他布局是准确的),最终使用它来重置列表的高度会删除的内容它。我看过很多关于这个的话题——其中一个提供了使布局中所有对象的高度为“wrap_content”的解决方案,例如,这对我不起作用。
我找不到任何适用于任何地方的东西。谁能帮忙?
真诚的,-李尔
最佳答案
经过大量搜索,我找到了这个线程:
How to force height of listView to be size so that every row is visible?
这给了我解决方案...有趣的是,我花了这么长时间才找到它,因为它比我之前在这个问题上浏览过的几十页要准确得多。
希望这有助于传播这个词:)
李尔
关于Android ListView item getMeasuredHeight() 返回的值比真实值小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19741521/
我正在尝试确定某些 UI 元素的实际尺寸(以像素为单位)! 这些元素是从 .xml 文件中扩展而来的,并使用倾斜宽度和高度进行初始化,以便 GUI 最终支持多种屏幕尺寸和 dpi (as recomm
我有这样的 XML: 我在方法 onMesure 中获取 View 高度,如下所示: protected void onMeasure(int widthMeasureSpec, int heig
我正在尝试以编程方式获取 ListView 中项目的高度。所以我在我们的网站上提到了一些电子邮寄,我得出了以下代码 private float calcListViewItemsHeight(
{ January 14, 2011... I have given up to use setListViewHeightBasedOnChildren(ListView listView},
我正在经历这个http://developer.android.com/guide/topics/ui/declaring-layout.html当我看到一条线表明高度可以但不一定与测量高度不同时,我
我整个上午都在为 Android 上的这个问题苦苦思索。我有一个 ListView,我需要为其计算高度。 我正在使用这段代码: int totalHeight = 0; for (int size =
我尝试在 onGlobalLayout 中调用 View.getMeasuredHeight 和 View.getHeight。两者都给了我相同的结果。 我想知道,在什么情况下它们的值会有所不同?有没
我正在尝试确定 TextView 在绘制之前 的高度。我正在使用以下代码来做到这一点: TextView textView = (TextView) findViewById(R.id.textvie
我真的对 android 为布局所做的整个测量事情感到困惑。基本上,我想在布局之前获取 View 的实际计算高度和宽度。我需要获得计算出的高度和宽度,因为我有一个隐藏的 LinearLayout,我想
ShadowSpan.java public class ShadowSpan extends ReplacementSpan { public ShadowSpan(int color, Point
我有一个问题。 我希望将行动态添加到 TableLayout。添加这些行时,我需要能够获取 View 的大小,因此我尝试在 onSizeChanged() 期间执行此操作,但新行不显示。所以我尝试了
我在 LinearLayout 中有一个 LinearLayout 并且子 linearlayout 有它的 layout params 其中 height 和 width 定义为 LinearLay
所以我正在搜索抛出所有 getHeight/widht 问题帖子,并尝试不同的方法来解决问题(如 globalLayoutListener 或 Runnable),等待,直到 FrameLayout
我写了一个非常简单的 View 组扩展 LinearLayout 如下。 @Override protected void onMeasure(int widthMeasureSpec, i
在使用 view.measure() 测量具有恒定尺寸 的View 之后,getMeasuredHeight() getMeasureWidth() 返回 0。 layout_view.xml,扩展以
我是一名优秀的程序员,十分优秀!