2011-04-20 10 views
0

라이너 및 관련 레이아웃의 기능을 이해합니다.Android : 레이아웃 안내

하지만 두 가지 모두로 내 requirment를 채울 수 있기 때문에 어떤 활동을 선택해야하는지 혼란 스럽습니다.

내가 에뮬레이터를 연구하면서 뭔가 놓친 것 같아요. 레이아웃을 사용할 때 지침이나 리트머스가 있습니까?

답변

2

이렇게 다양한보기가 중첩됩니다. 이 예제에서는 뷰를 쉽게 스크롤 할 수 있도록 가장 낮은 레벨에서 ScrollView를 사용한다는 것을 알 수 있습니다.

그런 다음 화면에 행 위젯을 단순히 쌓을 수 있도록 scrollview의 선형 레이아웃 ontop을 사용합니다.

마지막으로 RelayLayout을 사용하여 "layout_alignParentBottom"매개 변수를 사용하고 뷰 아래쪽에 단추를 표시 할 수 있습니다.

<?xml version="1.0" encoding="utf-8"?> 

<!-- use ScrollView incase it doesn't fit on small display --> 
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
      android:orientation="vertical" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:fillViewport="true" 
      android:background="#fffcb95a"> 

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

     <!-- Hello World --> 
     <TextView android:text="Hello World" 
        android:id="@+id/TextViewHeaderMessage1" 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:paddingTop="8dip" 
        android:textAppearance="?android:attr/textAppearanceLarge" 
        android:gravity="center_horizontal" 
        android:paddingBottom="30dip" 
        android:textColor="#6a7349" /> 



     <RelativeLayout android:orientation="horizontal" 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content"> 

      <!-- "OK" BUTTON --> 
      <Button android:text="OK" 
        android:id="@+id/ok_button" 
        android:layout_width="150dip" 
        android:layout_height="wrap_content" 
        android:layout_alignParentBottom="true" 
        android:layout_centerHorizontal="true" /> 

     </RelativeLayout> 

    </LinearLayout> 

</ScrollView> 
1

어느 쪽도 다른 것보다 본질적으로 더 ... 당신이 RelativeLayouts 더 유연 ... 서로에 대해 객체의 위치를 ​​많이 할 건데 경우 RelativeLayout의를 사용하지만에 좀 더 조심 올바르게 정렬하십시오 ... LinearLayout은 깔끔하게 수평 또는 수직으로 배치 할 수있는 항목이있는 경우에 더 쉽습니다 ... 어느 쪽이든 작업하면 가장 편안하게 작업 할 수 있습니다.

1

일반적으로 하나 또는 두 개의보기 만 사용할 수있는 경우보기가 간단하면 LinearLayout을 사용할 수 있습니다. 그러나 자신이 LinearLayout을 많이 중첩하는 것을 발견하면 RelativeLayout을 사용하여 전환해야한다는 신호입니다. 많은 LinearLayout보다 작은 단일 RelativeLayout을 사용하는 것이 더 효율적입니다.

레이아웃이 어떻게 생겼는지에 대한 예를 제공하면 더 구체적인 조언을 제공 할 수 있습니다.