2012-02-25 2 views
2

XML에서 오는 사용자 정의보기를 원합니다.xml에서 사용자 정의보기 만들기

여기 내 XML의 :

<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" > 
    <TextView 
     android:id="@+id/movieTitle" 
     android:text="@string/movietitle" 
     android:textSize="35dp" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:gravity="center" 
     /> 
    <com.galite.headliner.views.LoaderImageView 
     android:id="@+id/moviePoster" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@id/movieTitle" 
     android:layout_centerHorizontal="true" 
     android:layout_marginTop="20dp" 
     android:layout_marginBottom="20dp" 
     android:contentDescription="@string/poster" 
     /> 
    <TextView 
     android:id="@+id/movieDescription" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="@string/description" 
     android:layout_below="@id/moviePoster" 
     android:gravity="center" 
     /> 
</RelativeLayout> 

그리고 난 내가 온 클릭하고 모든 것을 같은 방법을 사용해야하기 때문에 사용자 정의보기로 팽창합니다.

여기 내 생성자의 :

public MyView(Context context, AttributeSet attrs, int defStyle) { 
    super(context, attrs, defStyle); 
    this.context = context; 
    initializeView(); 
} 

public void initializeView(){ 
    inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
    v = inflater.inflate(R.layout.movie, null); 
} 

가 어떻게 V에 MYVIEW 동일 할 수 ?

답변

2

당신은 다음과 같이 MyView에 부풀려 v를 첨부해야합니다 :

v = inflater.inflate(R.layout.movie, this, true); 

당신은 정확한 레이아웃은 다음 RelativeLayout를 확장하고이 같은 XML 레이아웃 수정 MyView를 만드는 것이하려면 다음

<merge xmlns:android="http://schemas.android.com/apk/res/android" > 
    <TextView 
     android:id="@+id/movieTitle" 
     android:text="@string/movietitle" 
     android:textSize="35dp" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:gravity="center" 
     /> 
    <com.galite.headliner.views.LoaderImageView 
     android:id="@+id/moviePoster" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@id/movieTitle" 
     android:layout_centerHorizontal="true" 
     android:layout_marginTop="20dp" 
     android:layout_marginBottom="20dp" 
     android:contentDescription="@string/poster" 
     /> 
    <TextView 
     android:id="@+id/movieDescription" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="@string/description" 
     android:layout_below="@id/moviePoster" 
     android:gravity="center" 
     /> 
</merge> 
+0

LayoutInflater 형식의 inflate (int, ViewGroup, boolean) 메서드가 인수 (int, MovieView, boolean)에 적용되지 않습니다. – Tsunaze

+0

@Tsunaze 죄송합니다. 답을 수정했습니다. – Luksprog

관련 문제