2012-10-22 4 views
1

내 애플 리케이션에 스크롤 배너가 포함되어있는 레이아웃이 있습니다. (아직 XML로 보면 finnished되지 않습니다.)이 배너는 다른 활동에서 사용됩니다. 그래서 나는 그것을 사용자 정의 레이아웃으로 만들어서 X 번 복사해서는 안된다. 여기 XML로 사용자 정의 레이아웃

이 레이아웃은 배너를 포함 지금

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="fill_parent" 
    android:layout_height="match_parent" 
    android:id="@+id/baseID"> 

    <RelativeLayout 
     android:layout_centerInParent="true" 
     android:layout_width="fill_parent" 
     android:layout_height="100dp" 
     android:id="@+id/id1" 
     android:background="#ff00ff"> 
     <Button 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:layout_marginLeft="25dp" 
      android:layout_marginRight="25dp"/> 
    </RelativeLayout> 

    <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="1dp" 
      android:layout_alignTop="@id/id1" 
      android:layout_alignBottom="@id/id1" 
      android:id="@+id/id2" 
      android:background="#08000000" 
      android:orientation="horizontal"> 

      <Button 
       android:id="@+id/button1" 
       android:layout_width="20dp" 
       android:layout_height="fill_parent" 
       android:layout_weight="1" 

       android:onClick="onClick" 
       android:text="1" /> 

      <TextView 
       android:layout_height="fill_parent" 
       android:layout_width="wrap_content" 
       android:text="to jest moj tekst" 
       android:layout_weight="16"/> 

      <Button 
       android:id="@+id/button2" 
       android:layout_width="20dp" 
       android:layout_height="fill_parent" 
       android:layout_weight="1" 

       android:onClick="onClick" 
       android:text="1" /> 

    </LinearLayout> 

</RelativeLayout> 

,하지만 더있을 것 (음 ... 나는 모든 올바른 그래서이 부분에서 비판이 감사 인 경우 확실하지 오전) 내 XML이다 물건.

질문은 다음과 같습니다. 어떻게 외부 수업에 배정합니까?

RelativeLayout (이 경우 int)을 확장하는 새로운 클래스를 만들어야한다는 것을 알고 있습니다. 그러나 그 때 무엇? 이 클래스에 레이아웃을 어떻게 설정합니까?

또한 약간의 연구를했지만 나는 이것을 위해 간단하고 정확한 튜토리얼을 찾지 못했습니다. 당신이 알고 있다면 - 그것을 게시하십시오.

답변

0

당신은 조각 작업을해야합니다 : http://developer.android.com/reference/android/app/Fragment.html

조각은 differents의 클래스로 VIEW/컨트롤러를 분리하는 개발자 수 있습니다.

그래서 XML에 differents 조각을 추가하고 각 조각은 자신의 구성 요소 (textview, button ...)를 담당하게됩니다. 더의 개발자 블로그를 참조 심지어에서

<include android:id="@+id/my_menu" layout="@layout/menu" /> 

처럼 포함 된 XML 레이아웃의 루트 태그의 속성을 다시 작성할 수

<include layout="@layout/menu" /> 

:

+0

그것에 대해 자세히 살펴볼 것입니다. 감사합니다 – user1763198

+0

파편은 이중창 활동에만 사용됩니까? – user1763198

+0

아니요, 조각은 원하는 모든 UI 요소 용입니다. – Stephane

관련 문제