【问题标题】:How to set the equal column width for gridview in android?如何在android中为gridview设置相等的列宽?
【发布时间】:2012-08-12 11:39:07
【问题描述】:

在我的应用程序中,我使用了gridview,textview 是gridview 的一个项目。列数 = 3,在此如何为所有列提供相等的宽度。 谁能帮帮我?

我的代码是:

网格视图: .........

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="0dip"
    android:layout_weight="1"
    android:gravity="center" >

    <GridView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/MyGrid"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="#ffffff"
        android:gravity="center_horizontal"
        android:horizontalSpacing="5dp"
        android:numColumns="3"
        android:padding="5dp"
        android:columnWidth="100dp"
        android:stretchMode="columnWidth"
        android:verticalSpacing="5dp" >
    </GridView>
</LinearLayout>

网格项目:

<TextView
    android:id="@+id/grid_item_text"
    android:layout_width="match_parent"
    android:layout_height="45dp"
    android:layout_weight="1"
    android:background="@drawable/btn_selected"
    android:gravity="center_horizontal|center_vertical"
    android:text="TextView"
    android:textColor="@color/BLACK"
    android:textSize="14dp" >
    </TextView>

</LinearLayout>

【问题讨论】:

  • 文本将从db动态流出。
  • 是的,我明白了。我已经为 textview 呈现的布局提供了“fill_parent”。并且没有为网格视图分配宽度。

标签: android gridview column-width


【解决方案1】:
<TextView
android:id="@+id/grid_item_text"
android:layout_width="45dp"
android:layout_height="45dp"
android:layout_weight="1"
android:background="@drawable/btn_selected"
android:gravity="center_horizontal|center_vertical"
android:text="TextView"
android:textColor="@color/BLACK"
android:textSize="14dp" >

【讨论】:

    猜你喜欢
    • 2011-10-10
    • 2014-01-19
    • 1970-01-01
    • 2015-11-23
    • 2020-11-28
    • 2017-09-13
    • 1970-01-01
    • 2015-09-02
    • 1970-01-01
    相关资源
    最近更新 更多