【问题标题】:How to set the screens size of Grid view to match all screen sizes?如何设置网格视图的屏幕尺寸以匹配所有屏幕尺寸?
【发布时间】:2015-02-20 08:26:01
【问题描述】:

这里我使用了gridview,但它并没有根据屏幕大小而改变。我认为height有问题。用于gridview的xml如下所示。

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:background="@drawable/bg"
android:orientation="vertical" >




<GridView
    android:id="@+id/gridView1"
     android:numColumns="3"
     android:gravity="center"
    android:paddingTop="20dp"
     android:horizontalSpacing="10dp"
     android:verticalSpacing="10dp"
     android:stretchMode="columnWidth"
    android:layout_width="match_parent"
    android:layout_height="fill_parent"
    android:layout_above="@+id/linearLayout1"
    android:layout_centerVertical="true"
     >
</GridView>


<LinearLayout
    android:id="@+id/linearLayout1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:orientation="vertical" >

    <com.assuretech.ku.HorizontalMenuBar
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />
</LinearLayout>

【问题讨论】:

    标签: android xml gridview


    【解决方案1】:

    </RelativeLayout>
    

    据我所知。您需要在最后关闭 RelativeLayout。我已经包含了我关闭的代码的屏幕截图。我将背景更改为红色以查看文字。

    【讨论】:

    • 我已经关闭了 relativelayout 标签..我在这里错过了..它必须为所有屏幕尺寸设置...
    【解决方案2】:

    我猜你在找

    numColumns = "auto_fit"

    作为 GridView 属性

    【讨论】:

      【解决方案3】:

      首先你必须使用一些布局来放置你的gridview。执行以下操作:

      使布局的高度和宽度填充父项:

      android:layout_width="fill_parent" android:layout_height="fill_parent" 然后,将 gridview 的高度和宽度也设置为 fill_parent。

      嗯,这只是一个假设的解决方案,您可能一直在以这种方式工作

      希望这对你有用。

      【讨论】:

        【解决方案4】:
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginBottom="10dp"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            android:layout_marginTop="30dp">
        
            <GridView
                android:id="@+id/grid_images"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:columnWidth="100dp"
                android:gravity="center"
                android:horizontalSpacing="10dp"
                android:numColumns="auto_fit"
                android:stretchMode="columnWidth"
                android:verticalSpacing="15dp">
        
            </GridView>
        
        </LinearLayout>
        

        【讨论】:

        • 对您的解决方案进行一些解释会很有用。
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-02-28
        • 2011-06-04
        • 1970-01-01
        相关资源
        最近更新 更多