[英]Gridview row height in android
我有一个gridview,它加载了textview,并且正在为文本视图设置背景图像。 我想根据某些逻辑来改变textviews的高度,但要保持gridview行的高度不变。 我尝试了此代码,但id无效。 电视是我的textview
int Height = 150 + Integer.parseInt(PostCount);
if(Height >= MaxHeight)
{
Height = MaxHeight;
}
tv.setLayoutParams(new GridView.LayoutParams(200, Height));
如果我使用以上内容,则行会重叠。 我也尝试了此操作而不设置gridview参数。
int Height = 150 + Integer.parseInt(PostCount);
if(Height >= MaxHeight)
{
Height = MaxHeight;
}
tv.setHeight(Height);
tv.setWidth(200);
这样只会创建宽度和高度均匀的网格视图。 我想要恒定的宽度,但是应该能够根据逻辑设置高度。 不知道我要去哪里错我不确定应该去表格布局还是网格布局。 帮助将不胜感激。
提前致谢。
不知道这是否有帮助,但也许可以将LinearLayout用作每行的父级,将textview用作子级。
在grid_item.xml中
<LinearLayout
android:layout_width="xdp" <!-- where x is the max width for each row -->
android:layout_height="ydp" <!-- where y is the max height for each row -->
<TextView
// rest of the definition for Textview
</TextView>
</LinearLayout>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.