在不同的旋转上调整GridView的大小

时间:2015-12-02 13:37:12

标签: android android-layout

只是处理一个简单的布局,我想知道是否有办法自动重新调整gridview的大小?

我的垂直旋转视图如下所示:

enter image description here

但是我的水平旋转视图看起来像是:

enter image description here

目前我的布局代码是:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="baegmon.mesmerize.GameActivity">


<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:text="Timer"
    android:id="@+id/textView_Timer"
    android:layout_alignParentTop="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentEnd="true" />



<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:text="Score"
    android:id="@+id/textView_Score"
    android:layout_alignParentTop="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true" />


<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:text="Question"
    android:layout_weight="1"
    android:id="@+id/textView_Question"
    android:layout_below="@+id/textView_Timer"
    android:layout_centerHorizontal="true" />

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@+id/textView_Question"
    android:layout_alignParentBottom="true">

    <GridView
        android:id="@+id/gridView_Game"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="0"
        android:columnWidth="100dp"
        android:drawSelectorOnTop="true"
        android:gravity="center"
        android:numColumns="5"
        android:stretchMode="columnWidth"
        android:verticalSpacing="5dp"
        android:clickable="true"
        android:layout_centerInParent = "true"
        />

</RelativeLayout>

有没有办法在水平视图中自动调整大小,以便所有GridView都适合布局?任何帮助将不胜感激。

谢谢。

1 个答案:

答案 0 :(得分:0)

问题不在GridView大小,而在GridView 单元格大小。

所有单元格都无法放入屏幕,因为每个单元格的高度更需要适合GridView的高度。这就是为什么GridView可以让你的内容滚动。

只是尝试更改单元格大小。

由于android:stretchMode="columnWidth",你的细胞因宽度而变得粗糙,这就是为什么在第二种情况下细胞之间有大的水平间距的原因。

尝试删除或替换该行。

相关问题