Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/223.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
android中的Gridview行高_Android_Gridview - Fatal编程技术网

android中的Gridview行高

android中的Gridview行高,android,gridview,Android,Gridview,我有一个gridview,其中加载了textview,我正在为文本视图设置背景图像。我想根据一些逻辑改变TextView的高度,但要保持gridview行的高度相同。我试过这个密码,但没用。电视是我的文本视图 int Height = 150 + Integer.parseInt(PostCount); if(Height >= MaxHeight) { Height = MaxHeight; } tv.setLayoutParams(new

我有一个gridview,其中加载了textview,我正在为文本视图设置背景图像。我想根据一些逻辑改变TextView的高度,但要保持gridview行的高度相同。我试过这个密码,但没用。电视是我的文本视图

    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>


嗨,谢谢。这确实有帮助。基本上,我用textview创建了一个列表项,在将其加载到网格视图时,我使用了AbsListView.LayoutParams,它成功了<代码>tv.setLayoutParams(新的AbsListView.LayoutParams(宽度、高度))