【问题标题】:Gridview row height in androidandroid中的Gridview行高
【发布时间】:2014-07-12 07:16:35
【问题描述】:

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

    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);

这只是创建具有均匀宽度和高度的网格视图。我想要恒定的宽度,但应该能够根据逻辑设置高度。不知道我哪里出错了。我不确定我应该使用表格布局还是网格布局。帮助将不胜感激。

提前致谢。

【问题讨论】:

    标签: android gridview


    【解决方案1】:

    不确定这是否会有所帮助,但可能使用 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(new AbsListView.LayoutParams(Width,Height));
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-23
    • 1970-01-01
    • 2016-01-18
    • 1970-01-01
    • 2013-10-15
    相关资源
    最近更新 更多