2014-04-10 2 views
0

내가 첫 번째 행에 다음과 같습니다 버튼 레이아웃 만들기 위해 노력하고 있습니다 :안드로이드 GridLayout과 - XML ​​- 열하지 비례

[ 1 ][2][3] 

버튼 1 버튼 2 배의 폭을 2 열을 점유하고 있어야한다 3. 버튼 2와 3은 동일한 너비 (1 열 너비) 여야합니다.

그러나, 내가 무엇을보고하고하는 것은 이것이다 : 버튼 3을 완전히 화면의 나머지 부분을 채우고 왜 버튼을 layout_column_span 규칙을 순종하는 것 같지 않는 이유

[1][2][  3  ] 

누군가가 말해 주시겠습니까? 그것은 GridLayout에 적지 않은 방식으로 공간을 배치에 관해서

<GridLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_gravity="center" 
    android:layout_margin="0dp" 
    android:adjustViewBounds="true" 
    android:alignmentMode="alignMargins" 
    android:clipToPadding="false" 
    android:columnCount="4" 
    android:fitsSystemWindows="false" 
    android:layoutMode="clipBounds" 
    android:orientation="horizontal" 
    android:padding="0dp" 
    android:rowCount="6" 
    android:useDefaultMargins="true" > 

     <Button 
      android:id="@+id/button1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="fill" 
      android:layout_weight="1" 
      android:layout_margin="0dp" 
      android:background="#ff0000" 
      android:layout_row="0" 
      android:layout_column="0" 
      android:layout_columnSpan="2" 
      android:layout_rowSpan="2"    
      android:text="1" /> 

     <Button 
      android:id="@+id/button2" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="fill" 
      android:layout_weight="1" 
      android:layout_margin="0dp" 
      android:background="#ffff00" 
      android:layout_row="0" 
      android:layout_column="2" 
      android:layout_columnSpan="1" 
      android:layout_rowSpan="2"    
      android:text="2" /> 

     <Button 
      android:id="@+id/button3" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_column="3" 
      android:layout_columnSpan="1" 
      android:layout_gravity="fill" 
      android:layout_margin="0dp" 
      android:layout_row="0" 
      android:layout_rowSpan="2" 
      android:layout_weight="1" 
      android:background="#00ff00" 
      android:text="3" /> 


</GridLayout> 

답변

0
Check this may help you 
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/favorites_grid" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:layout_gravity="center" 
android:columnCount="1" 
android:rowCount="2" 
> 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_column="0" 
    android:layout_gravity="left|top" 
    android:layout_row="0" 
    android:orientation="horizontal" 
    android:weightSum="4" > 

    <Button 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="2" 
     android:text="Cell 1" 
     android:textSize="14dip" /> 

    <Button 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:text="Cell 2" /> 

    <Button 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:text="Cell 3" 
     android:textSize="14dip" /> 
</LinearLayout> 

+0

감사합니다. 그러나 GridLayout을 사용하고 싶습니다. – SparkyNZ

0

this post에 따르면, 몇 가지 제한이 있습니다. 다른 방법을 시도하거나 각 행에 LinearLayout을 사용할 수 있으므로 해당 하위의 가중치를 제어 할 수 있습니다 Views.

<GridLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:columnCount="1" > 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal" 
    android:weightSum="4" > 

    <Button 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center" 
     android:layout_weight="2" 
     android:singleLine="true" 
     android:text="Button 1" /> 

    <Button 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center" 
     android:layout_weight="1" 
     android:singleLine="true" 
     android:text="Button 2" /> 

    <Button 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center" 
     android:layout_weight="1" 
     android:singleLine="true" 
     android:text="Button 3" /> 
</LinearLayout> 

희망이 당신을 도움이하기 : 여기

귀하의 경우에 대한 예입니다.

+0

난 그냥 런타임에 동적으로 크기를 설정해야 할 것 같아요. "컬럼 스팬"의 좋아하는 것을 지정할 수있는 바보 같지만 아직 한 컬럼은 두 컬럼보다 더 넓어 질 수 있습니다. 나는 열이 인접한 뷰에 의존성이 있다는 것을 알고 있지만 문제가 무엇인지 여기에서 볼 수는 없다. 여기이 기사는 계산기 스타일 단추를 배치하는 데 좋은 일을합니다. 채우기/중력과 관련된 것이 아닌 한 내 이유가 미쳐 있는지 확실하지 않습니다. http://code.tutsplus.com/tutorials/android-user-interface-design-creating-a-numeric-keypad-with-gridlayout--mobile -8677 – SparkyNZ