2012-02-27 4 views
1

저는 초보 개발자입니다. 제 기대치에 맞는 레이아웃을 만들었지 만, 너무 복잡하다는 두려움이 있습니다.레이아웃을 어떻게 단순화 할 수 있습니까?

많은 레이아웃을 사용했지만 선형 레이아웃과 상대 레이아웃을 혼합하지 않고 비슷한 레이아웃을 작성하는 방법을 알지 못합니다.

이 레이아웃을 어떻게 단순화 할 수 있습니까? 아이디어를 제공해 주셔서 감사합니다.

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:background="#ffffff" > 

<LinearLayout 
    android:id="@+id/header" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:background="@drawable/black_blue_gradient" 
    android:paddingBottom="5dip" 
    android:paddingTop="24dip" > 
</LinearLayout> 

<LinearLayout 
    android:id="@+id/linearLayout1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentRight="true" 
    android:layout_below="@+id/header" > 

    <LinearLayout 
     android:id="@+id/linearlayout01left" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_weight="40" 
     android:orientation="horizontal" > 

     <RelativeLayout 
      android:id="@+id/relativeLayout1" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" > 

      <LinearLayout 
       android:id="@+id/footer" 
       android:layout_width="fill_parent" 
       android:layout_height="8dp" 
       android:layout_alignParentBottom="true" 
       android:background="@drawable/b_bgradient" > 
      </LinearLayout> 

      <ImageView 
       android:id="@+id/imageView1" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_above="@+id/footer" 
       android:layout_alignParentLeft="true" 
       android:layout_alignParentRight="true" 
       android:layout_alignParentTop="true" 
       android:src="@drawable/oranwall_ovosh" /> 
     </RelativeLayout> 
    </LinearLayout> 

    <LinearLayout 
     android:id="@+id/linearlayout02right" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_weight="60" 
     android:orientation="horizontal" > 

     <TextView 
      android:id="@+id/textView1" 
      android:layout_width="wrap_content" 
      android:layout_height="match_parent" 
      android:background="#E9EEF2" 
      android:gravity="center_vertical|center_horizontal" 
      android:text="@string/My_txt" 
      android:textColor="#535A5F" 
      android:textSize="14sp" /> 
    </LinearLayout> 
</LinearLayout> 

</RelativeLayout> 
+0

원하는 결과를 얻으려면 여러 레이아웃을 사용할 때 아무 문제가 없습니다. 최종 컴파일 된 응용 프로그램에서 XML은 바이너리 형식으로 저장되며로드는 매우 빠릅니다. 두 개의 빈 LinearLayouts (머리글과 바닥 글)가 있습니다 - 목적은 무엇입니까? 삭제할 수 있습니까? –

답변

2

그것을보십시오. 배경 및 기타 리소스를 놓는 것을 잊지 마십시오.

 <?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:orientation="vertical" > 

    <TableRow 
     android:id="@+id/header" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:background="@drawable/ic_launcher"> 
    </TableRow> 

    <TableRow 
     android:id="@+id/body" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_weight="3"> 

     <LinearLayout 
      android:id="@+id/linearLayout1" 
      android:layout_width="wrap_content" 
      android:layout_height="fill_parent" > 

      <LinearLayout 
       android:id="@+id/linearLayout2" 
       android:layout_width="wrap_content" 
       android:layout_height="fill_parent" 
       android:orientation="vertical" > 

       <ImageView 
        android:id="@+id/imageView1" 
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent" 
        android:layout_weight="1" 
        android:src="@drawable/perm" /> 

       <TableRow 
        android:id="@+id/footer" 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:layout_weight="0.5" 
        android:background="@drawable/ic_launcher" > 
       </TableRow> 

      </LinearLayout> 

     </LinearLayout> 

     <TextView 
      android:id="@+id/textView1" 
      android:layout_width="wrap_content" 
      android:layout_height="fill_parent" 
      android:gravity="center" 
      android:text="Medium Text" 
      android:textAppearance="?android:attr/textAppearanceMedium" /> 

    </TableRow> 

</LinearLayout> 
+0

TableRow를 사용하는 이유는 무엇입니까? – Knossos

+0

왜 안 되니? 나는 많은 경우에 레이아웃 모양을 제어하는 ​​것이 편리하다는 것을 알았습니다. –

+0

멋진 생각이지만, 내 꼬리말은 왼쪽 부분 아래에만있을 수 있습니다. –

1

몇 가지 변경 내가 만들 것 같습니다

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="#ffffff" 
    android:orientation="vertical" > 

    <!-- I don't understand the point of this one: --> 
    <LinearLayout 
     android:id="@+id/header" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="@drawable/black_blue_gradient" 
     android:paddingBottom="5dip" 
     android:paddingTop="24dip" > 
    </LinearLayout> 

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

     <LinearLayout 
      android:id="@+id/linearlayout01left" 
      android:layout_width="0dip" 
      android:layout_height="match_parent" 
      android:layout_weight="0.4" 
      android:orientation="horizontal" > 

      <RelativeLayout 
       android:id="@+id/relativeLayout1" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" > 

       <!-- I don't understand the point of this one --> 
       <LinearLayout 
        android:id="@+id/footer" 
        android:layout_width="match_parent" 
        android:layout_height="8dp" 
        android:layout_alignParentBottom="true" 
        android:background="@drawable/b_bgradient" > 
       </LinearLayout> 

       <ImageView 
        android:id="@+id/imageView1" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:layout_above="@+id/footer" 
        android:layout_alignParentLeft="true" 
        android:layout_alignParentTop="true" 
        android:src="@drawable/oranwall_ovosh" /> 
      </RelativeLayout> 
     </LinearLayout> 

     <LinearLayout 
      android:id="@+id/linearlayout02right" 
      android:layout_width="0dip" 
      android:layout_height="match_parent" 
      android:layout_weight="0.6" 
      android:orientation="horizontal" > 

      <TextView 
       android:id="@+id/textView1" 
       android:layout_width="wrap_content" 
       android:layout_height="match_parent" 
       android:background="#E9EEF2" 
       android:gravity="center_vertical|center_horizontal" 
       android:text="@string/My_txt" 
       android:textColor="#535A5F" 
       android:textSize="14sp" /> 
     </LinearLayout> 
    </LinearLayout> 

</LinearLayout> 
+0

지금은 단지 저하 된 것만 포함하고 있습니다. (사용자가 앱에서 찾을 수 있도록 색상 코드를 사용합니다.) 동의합니다. 배경이있는 TextView로 쉽게 대체 할 수 있습니다. –

관련 문제