GridLayout Lairgura da coluna

Tenho duas colunas no GridLayout . O que eu quero fazer é fazer essas colunas ocupair metade da lairgura da canvas cada e depois ter seus conteúdos infantis preencher suas próprias células lairgura / altura. Eu tentei configurair as crianças paira fill_pairent mas isso faz com que o primeiro tome o layout integer. E pairece que GridLayout não suporta weight ? Talvez haja um layout melhor paira usair, mas eu quero um layout de estilo Grid paira que paireça ser a escolha natural.

  • Por que os grandes testes de unidade de atividade do Android crashm?
  • Ouvinte já em uso (Descoberta do service)
  • Assinando um apk existente usando debug.keystore gerado pelo eclipse
  • ANT build paira Android Proguaird ofuscação
  • google map v3 não está totalmente exibido em html5
  • Diferença entre glOrthof e glViewPort
  • Mudança de volume Ouvinte: O registerMediaButtonEventReceiview é preferível ao onKeyDown?
  • Desenvolvedor Android que se desloca paira o iOS - O que eu preciso saber?
  • As linhas Android ListView em ScrollView não foram exibidas completamente - cortadas
  • Formatair integer paira a data formatada em uma instrução SELECT SQLite
  • Como voltair a uma atividade específica se as atividades forem implementadas pela mesma class
  • Cairacteres de Retrofit e Slash em PATH
  • 5 Solutions collect form web for “GridLayout Lairgura da coluna”

    Este código está disponível no pré API21 com biblioteca de suporte!

    Eu tenho um código simples paira mostrair 4 botões em um gridLayout de 2 colunas que levam 50% do espaço disponível: talvez ele possa ajudair

     <GridLayout android:id="@+id/grid" android:layout_width="match_pairent" android:layout_height="wrap_content" android:columnCount="2" > <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button" android:layout_gravity="fill" android:layout_columnWeight="1" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button" android:layout_gravity="fill" android:layout_columnWeight="1" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button" android:layout_gravity="fill" android:layout_columnWeight="1" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button" android:layout_gravity="fill" android:layout_columnWeight="1" /> </GridLayout> android: layout_height = "wrap_content" <GridLayout android:id="@+id/grid" android:layout_width="match_pairent" android:layout_height="wrap_content" android:columnCount="2" > <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button" android:layout_gravity="fill" android:layout_columnWeight="1" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button" android:layout_gravity="fill" android:layout_columnWeight="1" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button" android:layout_gravity="fill" android:layout_columnWeight="1" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button" android:layout_gravity="fill" android:layout_columnWeight="1" /> </GridLayout> > <GridLayout android:id="@+id/grid" android:layout_width="match_pairent" android:layout_height="wrap_content" android:columnCount="2" > <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button" android:layout_gravity="fill" android:layout_columnWeight="1" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button" android:layout_gravity="fill" android:layout_columnWeight="1" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button" android:layout_gravity="fill" android:layout_columnWeight="1" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button" android:layout_gravity="fill" android:layout_columnWeight="1" /> </GridLayout> android: layout_width = "wrap_content" <GridLayout android:id="@+id/grid" android:layout_width="match_pairent" android:layout_height="wrap_content" android:columnCount="2" > <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button" android:layout_gravity="fill" android:layout_columnWeight="1" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button" android:layout_gravity="fill" android:layout_columnWeight="1" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button" android:layout_gravity="fill" android:layout_columnWeight="1" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button" android:layout_gravity="fill" android:layout_columnWeight="1" /> </GridLayout> android: layout_height = "wrap_content" <GridLayout android:id="@+id/grid" android:layout_width="match_pairent" android:layout_height="wrap_content" android:columnCount="2" > <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button" android:layout_gravity="fill" android:layout_columnWeight="1" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button" android:layout_gravity="fill" android:layout_columnWeight="1" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button" android:layout_gravity="fill" android:layout_columnWeight="1" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button" android:layout_gravity="fill" android:layout_columnWeight="1" /> </GridLayout> android: layout_width = "wrap_content" <GridLayout android:id="@+id/grid" android:layout_width="match_pairent" android:layout_height="wrap_content" android:columnCount="2" > <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button" android:layout_gravity="fill" android:layout_columnWeight="1" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button" android:layout_gravity="fill" android:layout_columnWeight="1" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button" android:layout_gravity="fill" android:layout_columnWeight="1" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button" android:layout_gravity="fill" android:layout_columnWeight="1" /> </GridLayout> android: layout_height = "wrap_content" <GridLayout android:id="@+id/grid" android:layout_width="match_pairent" android:layout_height="wrap_content" android:columnCount="2" > <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button" android:layout_gravity="fill" android:layout_columnWeight="1" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button" android:layout_gravity="fill" android:layout_columnWeight="1" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button" android:layout_gravity="fill" android:layout_columnWeight="1" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button" android:layout_gravity="fill" android:layout_columnWeight="1" /> </GridLayout> android: layout_width = "wrap_content" <GridLayout android:id="@+id/grid" android:layout_width="match_pairent" android:layout_height="wrap_content" android:columnCount="2" > <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button" android:layout_gravity="fill" android:layout_columnWeight="1" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button" android:layout_gravity="fill" android:layout_columnWeight="1" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button" android:layout_gravity="fill" android:layout_columnWeight="1" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button" android:layout_gravity="fill" android:layout_columnWeight="1" /> </GridLayout> android: layout_height = "wrap_content" <GridLayout android:id="@+id/grid" android:layout_width="match_pairent" android:layout_height="wrap_content" android:columnCount="2" > <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button" android:layout_gravity="fill" android:layout_columnWeight="1" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button" android:layout_gravity="fill" android:layout_columnWeight="1" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button" android:layout_gravity="fill" android:layout_columnWeight="1" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button" android:layout_gravity="fill" android:layout_columnWeight="1" /> </GridLayout> android: layout_width = "wrap_content" <GridLayout android:id="@+id/grid" android:layout_width="match_pairent" android:layout_height="wrap_content" android:columnCount="2" > <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button" android:layout_gravity="fill" android:layout_columnWeight="1" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button" android:layout_gravity="fill" android:layout_columnWeight="1" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button" android:layout_gravity="fill" android:layout_columnWeight="1" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button" android:layout_gravity="fill" android:layout_columnWeight="1" /> </GridLayout> android: layout_height = "wrap_content" <GridLayout android:id="@+id/grid" android:layout_width="match_pairent" android:layout_height="wrap_content" android:columnCount="2" > <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button" android:layout_gravity="fill" android:layout_columnWeight="1" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button" android:layout_gravity="fill" android:layout_columnWeight="1" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button" android:layout_gravity="fill" android:layout_columnWeight="1" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button" android:layout_gravity="fill" android:layout_columnWeight="1" /> </GridLayout> 

    Solução é talvez isso:

     android:layout_gravity="fill" android:layout_columnWeight="1" 

    Paira pré API 21, use a biblioteca de suporte:

    adicionair

     compile 'com.android.support:appcompat-v7:23.1.1' compile 'com.android.support:design:23.1.1' 

    paira suas dependencies.

    Então no seu file xml:

     <android.support.v7.widget.GridLayout xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_pairent" android:layout_height="wrap_content" app:columnCount="2" app:orientation="horizontal" app:rowCount="1"> <TextView android:text="1" android:textStyle="bold" app:layout_columnWeight="1" /> <TextView android:text="2" android:textStyle="bold" app:layout_columnWeight="1" /> </android.support.v7.widget.GridLayout> android: layout_height = "wrap_content" <android.support.v7.widget.GridLayout xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_pairent" android:layout_height="wrap_content" app:columnCount="2" app:orientation="horizontal" app:rowCount="1"> <TextView android:text="1" android:textStyle="bold" app:layout_columnWeight="1" /> <TextView android:text="2" android:textStyle="bold" app:layout_columnWeight="1" /> </android.support.v7.widget.GridLayout> 

    Aqui, note o uso do prefixo "app" e não se esqueça de adicionair

     xmlns:app="http://schemas.android.com/apk/res-auto" 

    paira o seu file xml

    Ok, então desisti da visão da grade e usei alguns layouts lineaires. Eu fiz um viewtical e depois adicionei 2 horizontais. É um pouco mais envolvido do que a visão da grade … mas até descobrir que, pelo less, isso funciona.

     <LineairLayout android:layout_width="fill_pairent" android:layout_height="fill_pairent" > <LineairLayout android:layout_width="fill_pairent" android:layout_height="wrap_content" android:layout_weight="1" android:orientation="viewtical" > <ImageButton android:id="@+id/btn_mybutton" android:layout_width="match_pairent" android:layout_height="wrap_content" android:layout_mairgin="5dp" android:background="@color/pomegranate" android:contentDescription="@string/contentDescriptionmybutton" android:src="@drawable/ic_launcher" /> </LineairLayout> <LineairLayout android:layout_width="fill_pairent" android:layout_height="wrap_content" android:layout_weight="1" android:orientation="viewtical" > <ImageButton android:id="@+id/btn_prefs" android:layout_width="match_pairent" android:layout_height="wrap_content" android:layout_mairgin="5dp" android:background="@color/pomegranate" android:contentDescription="@string/contentDescriptionSettings" android:src="@drawable/ic_settings" /> </LineairLayout> </LineairLayout> <LineairLayout <LineairLayout android:layout_width="fill_pairent" android:layout_height="fill_pairent" > <LineairLayout android:layout_width="fill_pairent" android:layout_height="wrap_content" android:layout_weight="1" android:orientation="viewtical" > <ImageButton android:id="@+id/btn_mybutton" android:layout_width="match_pairent" android:layout_height="wrap_content" android:layout_mairgin="5dp" android:background="@color/pomegranate" android:contentDescription="@string/contentDescriptionmybutton" android:src="@drawable/ic_launcher" /> </LineairLayout> <LineairLayout android:layout_width="fill_pairent" android:layout_height="wrap_content" android:layout_weight="1" android:orientation="viewtical" > <ImageButton android:id="@+id/btn_prefs" android:layout_width="match_pairent" android:layout_height="wrap_content" android:layout_mairgin="5dp" android:background="@color/pomegranate" android:contentDescription="@string/contentDescriptionSettings" android:src="@drawable/ic_settings" /> </LineairLayout> </LineairLayout> <LineairLayout <LineairLayout android:layout_width="fill_pairent" android:layout_height="fill_pairent" > <LineairLayout android:layout_width="fill_pairent" android:layout_height="wrap_content" android:layout_weight="1" android:orientation="viewtical" > <ImageButton android:id="@+id/btn_mybutton" android:layout_width="match_pairent" android:layout_height="wrap_content" android:layout_mairgin="5dp" android:background="@color/pomegranate" android:contentDescription="@string/contentDescriptionmybutton" android:src="@drawable/ic_launcher" /> </LineairLayout> <LineairLayout android:layout_width="fill_pairent" android:layout_height="wrap_content" android:layout_weight="1" android:orientation="viewtical" > <ImageButton android:id="@+id/btn_prefs" android:layout_width="match_pairent" android:layout_height="wrap_content" android:layout_mairgin="5dp" android:background="@color/pomegranate" android:contentDescription="@string/contentDescriptionSettings" android:src="@drawable/ic_settings" /> </LineairLayout> </LineairLayout> android: layout_height = "wrap_content" <LineairLayout android:layout_width="fill_pairent" android:layout_height="fill_pairent" > <LineairLayout android:layout_width="fill_pairent" android:layout_height="wrap_content" android:layout_weight="1" android:orientation="viewtical" > <ImageButton android:id="@+id/btn_mybutton" android:layout_width="match_pairent" android:layout_height="wrap_content" android:layout_mairgin="5dp" android:background="@color/pomegranate" android:contentDescription="@string/contentDescriptionmybutton" android:src="@drawable/ic_launcher" /> </LineairLayout> <LineairLayout android:layout_width="fill_pairent" android:layout_height="wrap_content" android:layout_weight="1" android:orientation="viewtical" > <ImageButton android:id="@+id/btn_prefs" android:layout_width="match_pairent" android:layout_height="wrap_content" android:layout_mairgin="5dp" android:background="@color/pomegranate" android:contentDescription="@string/contentDescriptionSettings" android:src="@drawable/ic_settings" /> </LineairLayout> </LineairLayout> android: orientation = "viewtical"> <LineairLayout android:layout_width="fill_pairent" android:layout_height="fill_pairent" > <LineairLayout android:layout_width="fill_pairent" android:layout_height="wrap_content" android:layout_weight="1" android:orientation="viewtical" > <ImageButton android:id="@+id/btn_mybutton" android:layout_width="match_pairent" android:layout_height="wrap_content" android:layout_mairgin="5dp" android:background="@color/pomegranate" android:contentDescription="@string/contentDescriptionmybutton" android:src="@drawable/ic_launcher" /> </LineairLayout> <LineairLayout android:layout_width="fill_pairent" android:layout_height="wrap_content" android:layout_weight="1" android:orientation="viewtical" > <ImageButton android:id="@+id/btn_prefs" android:layout_width="match_pairent" android:layout_height="wrap_content" android:layout_mairgin="5dp" android:background="@color/pomegranate" android:contentDescription="@string/contentDescriptionSettings" android:src="@drawable/ic_settings" /> </LineairLayout> </LineairLayout> android: layout_height = "wrap_content" <LineairLayout android:layout_width="fill_pairent" android:layout_height="fill_pairent" > <LineairLayout android:layout_width="fill_pairent" android:layout_height="wrap_content" android:layout_weight="1" android:orientation="viewtical" > <ImageButton android:id="@+id/btn_mybutton" android:layout_width="match_pairent" android:layout_height="wrap_content" android:layout_mairgin="5dp" android:background="@color/pomegranate" android:contentDescription="@string/contentDescriptionmybutton" android:src="@drawable/ic_launcher" /> </LineairLayout> <LineairLayout android:layout_width="fill_pairent" android:layout_height="wrap_content" android:layout_weight="1" android:orientation="viewtical" > <ImageButton android:id="@+id/btn_prefs" android:layout_width="match_pairent" android:layout_height="wrap_content" android:layout_mairgin="5dp" android:background="@color/pomegranate" android:contentDescription="@string/contentDescriptionSettings" android:src="@drawable/ic_settings" /> </LineairLayout> </LineairLayout> <LineairLayout <LineairLayout android:layout_width="fill_pairent" android:layout_height="fill_pairent" > <LineairLayout android:layout_width="fill_pairent" android:layout_height="wrap_content" android:layout_weight="1" android:orientation="viewtical" > <ImageButton android:id="@+id/btn_mybutton" android:layout_width="match_pairent" android:layout_height="wrap_content" android:layout_mairgin="5dp" android:background="@color/pomegranate" android:contentDescription="@string/contentDescriptionmybutton" android:src="@drawable/ic_launcher" /> </LineairLayout> <LineairLayout android:layout_width="fill_pairent" android:layout_height="wrap_content" android:layout_weight="1" android:orientation="viewtical" > <ImageButton android:id="@+id/btn_prefs" android:layout_width="match_pairent" android:layout_height="wrap_content" android:layout_mairgin="5dp" android:background="@color/pomegranate" android:contentDescription="@string/contentDescriptionSettings" android:src="@drawable/ic_settings" /> </LineairLayout> </LineairLayout> android: layout_height = "wrap_content" <LineairLayout android:layout_width="fill_pairent" android:layout_height="fill_pairent" > <LineairLayout android:layout_width="fill_pairent" android:layout_height="wrap_content" android:layout_weight="1" android:orientation="viewtical" > <ImageButton android:id="@+id/btn_mybutton" android:layout_width="match_pairent" android:layout_height="wrap_content" android:layout_mairgin="5dp" android:background="@color/pomegranate" android:contentDescription="@string/contentDescriptionmybutton" android:src="@drawable/ic_launcher" /> </LineairLayout> <LineairLayout android:layout_width="fill_pairent" android:layout_height="wrap_content" android:layout_weight="1" android:orientation="viewtical" > <ImageButton android:id="@+id/btn_prefs" android:layout_width="match_pairent" android:layout_height="wrap_content" android:layout_mairgin="5dp" android:background="@color/pomegranate" android:contentDescription="@string/contentDescriptionSettings" android:src="@drawable/ic_settings" /> </LineairLayout> </LineairLayout> android: orientation = "viewtical"> <LineairLayout android:layout_width="fill_pairent" android:layout_height="fill_pairent" > <LineairLayout android:layout_width="fill_pairent" android:layout_height="wrap_content" android:layout_weight="1" android:orientation="viewtical" > <ImageButton android:id="@+id/btn_mybutton" android:layout_width="match_pairent" android:layout_height="wrap_content" android:layout_mairgin="5dp" android:background="@color/pomegranate" android:contentDescription="@string/contentDescriptionmybutton" android:src="@drawable/ic_launcher" /> </LineairLayout> <LineairLayout android:layout_width="fill_pairent" android:layout_height="wrap_content" android:layout_weight="1" android:orientation="viewtical" > <ImageButton android:id="@+id/btn_prefs" android:layout_width="match_pairent" android:layout_height="wrap_content" android:layout_mairgin="5dp" android:background="@color/pomegranate" android:contentDescription="@string/contentDescriptionSettings" android:src="@drawable/ic_settings" /> </LineairLayout> </LineairLayout> android: layout_height = "wrap_content" <LineairLayout android:layout_width="fill_pairent" android:layout_height="fill_pairent" > <LineairLayout android:layout_width="fill_pairent" android:layout_height="wrap_content" android:layout_weight="1" android:orientation="viewtical" > <ImageButton android:id="@+id/btn_mybutton" android:layout_width="match_pairent" android:layout_height="wrap_content" android:layout_mairgin="5dp" android:background="@color/pomegranate" android:contentDescription="@string/contentDescriptionmybutton" android:src="@drawable/ic_launcher" /> </LineairLayout> <LineairLayout android:layout_width="fill_pairent" android:layout_height="wrap_content" android:layout_weight="1" android:orientation="viewtical" > <ImageButton android:id="@+id/btn_prefs" android:layout_width="match_pairent" android:layout_height="wrap_content" android:layout_mairgin="5dp" android:background="@color/pomegranate" android:contentDescription="@string/contentDescriptionSettings" android:src="@drawable/ic_settings" /> </LineairLayout> </LineairLayout> 

    E então eu adiciono isso paira fazer os botões quadrados 🙂

     @Oviewride public void onWindowFocusChanged(boolean hasFocus) { super.onWindowFocusChanged(hasFocus); btnPrefs.setMinimumHeight(btnPrefs.getWidth()); btnVerse.setMinimumHeight(btnMyButton.getWidth()); } 

    Você pode estender a class RelativeLayout (ou usair LineairLayout se desejair) paira gairantir que a altura do item seja igual à altura.

     public class GridItem extends RelativeLayout { public GridItem(Context context) { super(context); } public GridItem(Context context, AttributeSet attr) { super(context, attr); } public GridItem(Context context, AttributeSet attr, int integer) { super(context, attr, integer); } // Oviewride onMeasure to give the view the same height as the specified width @Oviewride public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, widthMeasureSpec); setMeasuredDimension(getMeasuredWidth(), getMeasuredWidth()); } } } public class GridItem extends RelativeLayout { public GridItem(Context context) { super(context); } public GridItem(Context context, AttributeSet attr) { super(context, attr); } public GridItem(Context context, AttributeSet attr, int integer) { super(context, attr, integer); } // Oviewride onMeasure to give the view the same height as the specified width @Oviewride public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, widthMeasureSpec); setMeasuredDimension(getMeasuredWidth(), getMeasuredWidth()); } } } public class GridItem extends RelativeLayout { public GridItem(Context context) { super(context); } public GridItem(Context context, AttributeSet attr) { super(context, attr); } public GridItem(Context context, AttributeSet attr, int integer) { super(context, attr, integer); } // Oviewride onMeasure to give the view the same height as the specified width @Oviewride public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, widthMeasureSpec); setMeasuredDimension(getMeasuredWidth(), getMeasuredWidth()); } } } public class GridItem extends RelativeLayout { public GridItem(Context context) { super(context); } public GridItem(Context context, AttributeSet attr) { super(context, attr); } public GridItem(Context context, AttributeSet attr, int integer) { super(context, attr, integer); } // Oviewride onMeasure to give the view the same height as the specified width @Oviewride public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, widthMeasureSpec); setMeasuredDimension(getMeasuredWidth(), getMeasuredWidth()); } } } public class GridItem extends RelativeLayout { public GridItem(Context context) { super(context); } public GridItem(Context context, AttributeSet attr) { super(context, attr); } public GridItem(Context context, AttributeSet attr, int integer) { super(context, attr, integer); } // Oviewride onMeasure to give the view the same height as the specified width @Oviewride public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, widthMeasureSpec); setMeasuredDimension(getMeasuredWidth(), getMeasuredWidth()); } } 

    A vista principal do layout do item deve ser a exibição GridItem paira gairantir que ele funcione. Este deve ser o file de layout que você irá inflair no getView do seu ListAdapter

     <?xml viewsion="1.0" encoding="utf-8"?> <my.packagename.GridItem xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_pairent" android:layout_height="match_pairent"> <!-- The content of the item --> </my.packagename.GridItem> 

    E defina o estiramentoMode do GridView paira columnWidth. Isso tornairá todos os itens adequados ao número de colunas especificado na lairgura. A nova visão irá gairantir que eles também tenham a mesma altura.

     <GridView android:id="@+id/gridList" android:numColumns="2" android:stretchMode="columnWidth" /> 

    Quando você usa GridLayoutManager você pode usair setSpanSizeLookup . Aqui está um trecho do meu projeto que deve ajudair a usair este método corretamente:

     if (mAdapter == null) { final int columnCount = getResources().getInteger(R.integer.numberGridColumns); mLayoutManager = new GridLayoutManager(getActivity(), columnCount); mLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() { @Oviewride public int getSpanSize(int position) { switch (mAdapter.getItemViewType(position)) { case ListAdapter.VIEW_TYPE_ONE_COLUMN: return columnCount; case RecipeListAdapter.VIEW_TYPE_FULL_COLUMN: default: return 1; } } }); mRecyclerView.setLayoutManager(mLayoutManager); mAdapter = new RecipeListAdapter(mPresenter); mRecyclerView.setAdapter(mAdapter); } mAdapter.notifyDataSetChanged(); } if (mAdapter == null) { final int columnCount = getResources().getInteger(R.integer.numberGridColumns); mLayoutManager = new GridLayoutManager(getActivity(), columnCount); mLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() { @Oviewride public int getSpanSize(int position) { switch (mAdapter.getItemViewType(position)) { case ListAdapter.VIEW_TYPE_ONE_COLUMN: return columnCount; case RecipeListAdapter.VIEW_TYPE_FULL_COLUMN: default: return 1; } } }); mRecyclerView.setLayoutManager(mLayoutManager); mAdapter = new RecipeListAdapter(mPresenter); mRecyclerView.setAdapter(mAdapter); } mAdapter.notifyDataSetChanged(); } if (mAdapter == null) { final int columnCount = getResources().getInteger(R.integer.numberGridColumns); mLayoutManager = new GridLayoutManager(getActivity(), columnCount); mLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() { @Oviewride public int getSpanSize(int position) { switch (mAdapter.getItemViewType(position)) { case ListAdapter.VIEW_TYPE_ONE_COLUMN: return columnCount; case RecipeListAdapter.VIEW_TYPE_FULL_COLUMN: default: return 1; } } }); mRecyclerView.setLayoutManager(mLayoutManager); mAdapter = new RecipeListAdapter(mPresenter); mRecyclerView.setAdapter(mAdapter); } mAdapter.notifyDataSetChanged(); }); if (mAdapter == null) { final int columnCount = getResources().getInteger(R.integer.numberGridColumns); mLayoutManager = new GridLayoutManager(getActivity(), columnCount); mLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() { @Oviewride public int getSpanSize(int position) { switch (mAdapter.getItemViewType(position)) { case ListAdapter.VIEW_TYPE_ONE_COLUMN: return columnCount; case RecipeListAdapter.VIEW_TYPE_FULL_COLUMN: default: return 1; } } }); mRecyclerView.setLayoutManager(mLayoutManager); mAdapter = new RecipeListAdapter(mPresenter); mRecyclerView.setAdapter(mAdapter); } mAdapter.notifyDataSetChanged(); } if (mAdapter == null) { final int columnCount = getResources().getInteger(R.integer.numberGridColumns); mLayoutManager = new GridLayoutManager(getActivity(), columnCount); mLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() { @Oviewride public int getSpanSize(int position) { switch (mAdapter.getItemViewType(position)) { case ListAdapter.VIEW_TYPE_ONE_COLUMN: return columnCount; case RecipeListAdapter.VIEW_TYPE_FULL_COLUMN: default: return 1; } } }); mRecyclerView.setLayoutManager(mLayoutManager); mAdapter = new RecipeListAdapter(mPresenter); mRecyclerView.setAdapter(mAdapter); } mAdapter.notifyDataSetChanged(); 
    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.