2014-04-07 4 views
0

아래 컨트롤 레이아웃의 경우 선형 레이아웃이 2 개인 상대 레이아웃을 사용하고 있습니다. 1 회색 배경의 B1, B2 및 B3에 대한 선형 레이아웃과 B4, B5 및 B6의 선형 레이아웃 1 개.Android : Relativelayout 행의 배경

상대적 레이아웃 내의 선형 레이아웃을 사용하면 렌더링 속도가 느려집니다.

어떻게 선형 레이아웃을 없앨 수 있습니까? 특히 B1, B2, B3 행에 대한 회색 배경을 얻을 수 없습니다. 아니면 이런 식으로 괜찮다고 생각하니? 모든 도움을 미리 감사드립니다.

enter image description here

편집 :

아래는 그냥 건물과 가능하면 하위 레이아웃을 제거하는 노력을 시작 내 XML이다. 당신의 XML, 당신은이 작업을 수행 할 수있는 유일한 방법을 보지 않고

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

    <ImageView 
     android:id="@+id/imageView1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentTop="true" 
     android:layout_marginLeft="15dp" 
     android:layout_marginTop="15dp" 
     android:src="@drawable/ic_launcher" /> 

    <ImageButton 
     android:id="@+id/imageButton1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentRight="true" 
     android:layout_alignParentTop="true" 
     android:src="@drawable/abc_ic_search_api_holo_light" /> 

    <TextView 
     android:id="@+id/textView1" 
     android:layout_width="60dp" 
     android:layout_height="60dp" 
     android:layout_below="@+id/imageButton1" 
     android:layout_centerHorizontal="true" 
     android:text=" Test Label" /> 

    <LinearLayout 
     android:id="@+id/linearLayout1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentRight="true" 
     android:layout_below="@+id/textView1" 
     android:layout_marginTop="54dp" 
     android:background="@android:color/darker_gray" > 

     <Button 
      android:id="@+id/button1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_below="@+id/textView1" 
      android:layout_toRightOf="@+id/linearLayout1" 
      android:text="Button" /> 

     <Button 
      android:id="@+id/button2" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignBaseline="@+id/button1" 
      android:layout_alignBottom="@+id/button1" 
      android:layout_marginLeft="18dp" 
      android:layout_toRightOf="@+id/imageView1" 
      android:text="Button" /> 

     <Button 
      android:id="@+id/button3" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignBaseline="@+id/button2" 
      android:layout_alignBottom="@+id/button2" 
      android:layout_toRightOf="@+id/button2" 
      android:text="Button" /> 
    </LinearLayout> 



    <LinearLayout 
     android:id="@+id/linearLayout2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_below="@+id/linearLayout1" 
     android:layout_marginTop="31dp" > 

     <Button 
      android:id="@+id/button6" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignBottom="@+id/button5" 
      android:layout_toLeftOf="@+id/imageButton1" 
      android:text="Button" /> 

     <Button 
      android:id="@+id/button4" 
      style="?android:attr/buttonStyleSmall" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignRight="@+id/linearLayout2" 
      android:layout_centerVertical="true" 
      android:text="Button" /> 

     <Button 
      android:id="@+id/button5" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_centerVertical="true" 
      android:layout_toRightOf="@+id/button4" 
      android:text="Button" /> 
    </LinearLayout> 

    <TextView 
     android:id="@+id/textView2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignRight="@+id/textView1" 
     android:layout_alignTop="@+id/listView1" 
     android:layout_marginRight="15dp" 
     android:text="TextView" /> 

    <ListView 
     android:id="@+id/listView1" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_below="@+id/linearLayout2" 
     android:layout_marginTop="18dp" > 
    </ListView>  

</RelativeLayout> 
+1

에는 XML 파일이 포함되어 있습니다. – Booger

답변

1

는, 버튼의 당신의 행을 포함하는 다른있는 LinearLayout을 포함하는 하나의 상대 레이아웃, 함께와있다.

올바른 동안, 중첩 된 레이아웃의 수를 제한하는 것이 좋습니다 (선형이 아닌 중첩 된 레이아웃).

이 경우, 행 배경을 설정하려면 적어도 하나의 중첩 된 LinearLayout이 필요하며 큰 문제는 아닙니다.

편집 : XML을 검토 한 결과, 원하는 것을 얻을 수있는 최선의 방법이라고 생각합니다.

+0

아직 작성중인 my xml로 질문을 업데이트했습니다. 하지만 당신의 설명이 그 대답 인 것 같습니다. 일단 XML을 검토하면이를 수락합니다. – kiran

+0

XML이 실제로 멋지게 보입니다. 기술적으로 linearLayout2 안에있는 3 개의 버튼을 부모 상대 레이아웃으로 이동할 수 있습니다. 나는 이것이 실제로 필요하다고 생각하지 않는다. 깊이있는 계층 구조 (즉, 깊이있는 중첩 수준)를 피해야한다는 것을 알아 두는 것이 중요하다. 너는 얕은 계층을 가지고 있기 때문에, 이것은 좋아 보인다. – Booger

+0

좋습니다. 설명 해줘서 고마워. 저는 새로운 사용자로서 투표를 할 수 없습니다. – kiran