2012-07-24 2 views
1

3 버튼을 연속으로 표시해야하고 3 버튼은
화면의 총 9 버튼을 의미합니다. Horizontal LinearLayout에서 각각 android : layout_weight 0.33을 할당합니다. 모든 화면과 호환되는
이지만 세로로 무게를 설정해야합니다.선형 레이아웃에서 수직으로 무게를 할당하는 방법은 무엇입니까?

간단히 말해서 9 버튼 하나의 화면을 만들어야하고 모든
화면과 호환되어야합니다. 어떻게해야합니까? 그렇다면 우리는 무게를 수직으로 설정할 수 있습니까?
미리 감사드립니다 ...

답변

1

3 개의 LinearLayouts를 각 행당 하나씩 만들고 세로 형 LinearLayout에 캡슐화하십시오. 그런 다음 3 개의 LinearLayouts에 같은 가중치를 부여하십시오.

의사 :

<VerticalLinearLayout> 

    <HorizontalLinearLayout> 
     <Button 1 /> 
     <Button 2 /> 
     <Button 3 /> 
    </HorizontalLinearLayout> 

    <HorizontalLinearLayout> 
     <Button 4 /> 
     <Button 5 /> 
     <Button 6 /> 
    </HorizontalLinearLayout> 

    <HorizontalLinearLayout> 
     <Button 7 /> 
     <Button 8 /> 
     <Button 9 /> 
    </HorizontalLinearLayout> 

</VerticalLinearLayout> 

하면 VerticalLinearLayout를 제외하고, 모든 3의 가중치를 부여합니다. 모든 layout_width 및 layout_height가 fill_parent로 설정되어 있는지 확인하십시오.

+0

어쩌면이 대답에보고 싶은데 : http://stackoverflow.com/a/4568183/191235 – Tom

+0

감사합니다! 그게 ..... 모든 휴대폰과 호환되는 화면을 디자인하는 다른 방법? –

+0

@sandiparmal 이것은 모든 안드로이드 폰에서 작동합니다. –

0

채굴 소스

<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_weight="1"> 

     <Button 
      android:id="@+id/btnSales" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_weight="1" 
      android:text="Sales" /> 

    </LinearLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_weight="1"> 
     <Button 
      android:id="@+id/btnProduction" 
      android:layout_width="wrap_content" 
      android:layout_height="match_parent" 
      android:layout_weight="1" 
      android:text="Production" /> 

    </LinearLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_weight="1"> 

     <Button 
      android:id="@+id/btnStock" 
      android:layout_width="wrap_content" 
      android:layout_height="match_parent" 
      android:layout_weight="1" 
      android:text="Stock" /> 

    </LinearLayout> 
</LinearLayout> 
관련 문제