GridView项目未在Android中完全显示

时间:2016-03-30 03:38:30

标签: android gridview

在我给出布局高度之前,所有GridView项目都没有显示出来。

不同xml中的相同设置可以正常工作。

如何在不给出高度的情况下显示所有项目。

它始终只显示两个项目。

请看下面我做了什么:

 <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:id="@+id/gridOptionsView"
                android:layout_marginBottom="10dp"
                android:visibility="gone"
                android:orientation="vertical" >

                <GridView
                    android:id="@+id/OptionsGrid"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:columnWidth="125dp"
                    android:horizontalSpacing="5dp"
                    android:layout_marginBottom="5dp"
                    android:scrollbars="vertical"
                    android:verticalSpacing="5dp"
                    android:numColumns="2"
                    android:visibility="visible">
                </GridView>

            </LinearLayout>

我在XML中有不同的Linearlayouts,其中一个如上所示。

我无法追踪此问题。

谢谢!

3 个答案:

答案 0 :(得分:2)

试试这个

您的源代码LinearLayout是主容器布局,因此此布局更改了此语句

android:layout_height =&#34; wrap_content&#34; android:layout_height =&#34; match_parent&#34;

所以但是当你将gridview高度设置为match_parent时。父布局Layout_height是wrap_content。因此,您的gridview将无法完全显示。在下面的代码中完成了更改

var app = angular.module('plunker', ['ngAnimate','ui.bootstrap']);

app.controller('MainCtrl', function($scope, $uibModal) {
    $scope.name = 'World';
    $scope.studentId = "123"
    $scope.reloadCallback = function(){
        alert("Call back")
    }
   $scope.showModal = function(){
      var modalInstance = $uibModal.open({
           templateUrl: 'deletestudent.html',
           controller: 'DeleteStudentCtrl as deleteStudent',
           backdrop  : 'static',
           keyboard  : false,
           resolve: {
               studentId: function () {
                   return $scope.studentId;
               }
           }
       });
       modalInstance.result.then(function (status) {
           if (status === 'ok'){
               $scope.reloadCallback();
           }
       });
    }
});

app.controller('DeleteStudentCtrl', function($scope, $uibModalInstance,    studentId) {
     console.log(studentId);
     $scope.closeMe = function(){
          $uibModalInstance.close('ok');
    }
})

答案 1 :(得分:1)

您的LinearLayout是父版式。

<LinearLayout>
    android:layout_height="wrap_content"
</LinearLayout>

GridView高度设置为match_parent

此处的父级布局为LinearLayout,其layout_heightwrap_content。因此,GridView不会以完整显示高度显示。

这样做。

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/gridOptionsView"
    android:layout_marginBottom="10dp"
    android:visibility="gone"
    android:orientation="vertical" >

    <GridView
        android:id="@+id/OptionsGrid"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:columnWidth="125dp"
        android:horizontalSpacing="5dp"
        android:layout_marginBottom="5dp"
        android:scrollbars="vertical"
        android:verticalSpacing="5dp"
        android:numColumns="2"
        android:visibility="visible">
    </GridView>
</LinearLayout>

答案 2 :(得分:0)

更改GridView高度

android:layout_height="match_parent"

android:layout_height="wrap_content"

相关问题