2013-11-21 4 views
0

나는 사용자 지정보기를 만들려고하고, 내가 확장 LinearLayout에서 :않도록 해제에 필요한보기 둥지

public class CustomView extends LinearLayout { 
    private ImageView mPrevImgView; 
    public CustomView(Context context, AttributeSet attrs) { 
     super(context, attrs); 
     View root = ((LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.custom, null); 
     this.addView(root); 

     mPrevImgView = root.findViewById(R.id.xx); 
     .... 
    } 
} 

그리고 layout/custom.xml :

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       android:orientation="vertical" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent"> 
    <ImageView 
     android:id="@+id/xx" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"/> 
    ....... 
</LinearLayout> 

그런 다음이 방법을 사용하려고합니다.

<CustomView android:layout_width.....> 
    ... 
</CustomView> 

이 예상대로 작동합니다.

그러나 CustomView 자체가 LinearLayout 것 같다, 그리고 그 다음 생성자에서 다른 LinearLayout 불필요 두 LinearLayout 중첩이 원인을 추가합니다. 이 문제를 피할 수 있는지 궁금합니다.

답변

0
// try this way 
**custom.xml** 
<ImageView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/xx" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:adjustViewBounds="true"/> 
+0

안녕하세요 PLZ 할 수 있습니다, 거기에 XML – hguser

+0

다른 뷰는 그런 다음 두 가지 옵션 중 하나가 모든 뷰 위와 같이 개인을 정의했다이며, 다른 하나는 이미 할 hguser @ –

+0

을 (부모 레이아웃에서 귀하의 모든보기를 넣어)입니다 그것은 당신에게 감사합니다 upvote ans 감사합니다 ... –