2017-01-05 3 views
1

어딘가에 어리석은 실수가 있음을 알고 있지만 어디에서 확인할 수 없습니다. 나는 컨테이너의 코드를 다음있어 :Android Studio에서 사용자 정의 컨테이너에보기를 넣지 않겠습니다.

public class ImagesView extends LinearLayout { 
public ImagesView(Context context, AttributeSet attrs) { 
    super(context, attrs); 
} 

public ImagesView(Context context) { 
    super(context); 
} 
@Override 
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 
    int widthMode = MeasureSpec.getMode(widthMeasureSpec); 
    int widthSize = MeasureSpec.getSize(widthMeasureSpec); 
    int heightMode = MeasureSpec.getMode(heightMeasureSpec); 
    int heightSize = MeasureSpec.getSize(heightMeasureSpec); 
    float ar=(float)896/768; 
    this.setMeasuredDimension(widthSize, (int) (widthSize/5*(1f/ar))); 
    //this.setMeasuredDimension(1280,240); 
} 
} 

레이아웃 XML : 안드로이드 스튜디오에서

<?xml version="1.0" encoding="utf-8"?> 
<com.rhyboo.net.test.ImagesView xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="horizontal" android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:background="@android:color/holo_red_light"> 

<Button 
    android:text="Button" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:id="@+id/button3" 
    android:layout_weight="1" /> 
</com.rhyboo.net.test.ImagesView> 

내 컨테이너의 크기가 올바르게 설정되어 볼 수 있습니다,하지만 난 용기에 무언가를 추가 할 경우이 같은 아이 뷰를 표시 제로 크기 : zero-sized child view

내가 뭘 잘못하고 있니?

+0

전체 레이아웃 코드를 제공해주십시오. – MemLeak

+0

예. 내 첫 글을 수정했습니다. 죄송합니다. – undefined

답변

2

onMeasure는 super.onMeasure ...를 호출하지 않으므로 칠레는 측정되지 않습니다. 부모 onMeasure를 호출 할 때 너비 및/또는 높이에 대해 모드를 정확히 설정하려고합니다.

+0

그랬다면 고마워요 .BTW 컨테이너에 모드를 설정하려면 어떻게해야합니까? – undefined

+0

해당 MeasureSpec.makeMeasureSpec.Thanks 다시! – undefined