2012-02-03 6 views
5

GridLayoutは常に、子を必要に応じてレイアウトにプッシュします。GridLayoutは子をプッシュダウンし、高さがfill_parentのときにオーバーフローします

<?xml version="1.0" encoding="utf-8"?> 
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:columnCount="3" 
    android:orientation="vertical" 
    android:rowCount="4" 
    android:useDefaultMargins="true" > 
... 
    <ImageView 
     android:id="@+id/main_image" 
     android:layout_column="1" 
     android:layout_columnSpan="2" 
     android:layout_row="3" 
     android:scaleType="fitStart" /> 
</GridLayout> 

GridLayoutはfill_parentを宣言しているので、オーバーフローしないと予想します。 GridLayoutは、この場合はウィンドウ(全高)である親のサイズを取る必要があります。しかし、階層ビューアでは、GridLayoutは垂直方向と水平方向の両方でWrap_contentとして設定されます。

このように、ImageView(大きな画像)またはテキストビューは、自分自身にフィットするようにプッシュされ、コンテナがオーバーフローします。

これは、コンテナのグリッドビューが親に合った階層ビューア内見ることができます:画像表示オーバーフロードキュメントを読ん

​​

ながら

container grid view

、私は理解して重力を設定する必要があります。私が試すことができる限り、重力オプションと画像スケーリングオプションを多用することなく使用しました。 useDefaultMargins="false"で余白を削除するとレイアウトのオーバーフローが変更され、問題がgridlayoutに向かいます。

私の質問は次のとおりです。

  • はこのバグですか、私は間違ってのGridLayoutを使用しています
  • 私は彼らのコンテナにフィットするようにして 残りのスペース
+0

は、私が最初の要素に明示的な高さを与える場合を除き、これはhttp://developer.android.com/resources/tutorials/views/hello-gridview.html – NagarjunaReddy

+0

私は、これと同じ問題を持っている、それが占め見ます全体の親は、表面の残りの部分をプッシュ... – sethro

答えて

0
を埋めるためのGridLayoutの子供たちを強制するにはどうすればよいです

他のレイアウトのトリックは、最初の要素にandroid:layout_weight = "1.0"を与え、他の要素には何も与えないことです。なぜそれが動作する私は分かりませんが、それはありません。 ImageView、TextView、Buttonを表示するシンプルなXMLがあります。 Layout_weightパラメータをImageViewに割り当てないと、テキストとボタンが下にシフトしました。

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="@color/white" 
    android:orientation="vertical" 
    android:keepScreenOn = "true" > 

    <ImageView 
     android:id="@+id/imageView_surprise" 
     android:layout_width="wrap_content" 
     android:layout_height="0dip" 
     android:scaleType="centerInside" 
     android:contentDescription="@string/accessibility_imageView_surprise" 
     android:layout_weight="1.0" /> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" 
     android:layout_gravity="bottom" > 

     <TextView 
      android:id="@+id/textView_message" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:textColor="@color/black" 
      android:textSize="24sp" 
      android:gravity="center_horizontal" /> 

     <Button 
      android:id="@+id/button_share" 
      style="@style/button_text" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" /> 

    </LinearLayout> 

</LinearLayout> 
関連する問題