2017-01-07 9 views
0

자신 만의 사용자 정의보기를 만들려고하고 있는데, 나는 onMeasure이 어떤 값으로 설정되어 있는지를 보여줍니다. 사용자 정의보기 안드로이드 onMeasure 방법은 레이아웃에 설정된 값을 두 배로 표시합니다.

@Override 
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 
     int parentWidth = MeasureSpec.getSize(widthMeasureSpec); 
     int parentHeight = MeasureSpec.getSize(heightMeasureSpec);//shows 200 
     this.setMeasuredDimension(parentWidth, parentHeight); 
     super.onMeasure(widthMeasureSpec, heightMeasureSpec); 
    } 

나는 parentHeight 또는 parentWidth 로그인

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:custom="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 
<com.customview.PercentageCircle 
    android:layout_width="match_parent" 
    android:layout_height="100dp" 
    custom:currentValue="0" 
    custom:maxValue="100" 
    custom:thickNess="80" 
    custom:fillBackgroundColor="@color/light_gray" 
    custom:fillColor="@color/red" 
    /> 

, 나는 두 번 지정된 value.I 얻을 그것의 원인을 이해할 수 없습니다입니다.

+0

당신은'android : layout_width = "match_parent"'를 어떻게 두배로 늘릴 수 있습니까? – pskink

+1

dp에서 100dp를 설정하면 픽셀 값이 표시됩니다. –

+0

예 (match_parent 및 wrap_content는 두 배가됩니다). –

답변

0

캔버스 기능에 대한 모든 입력은 픽셀 단위입니다. onMeasure의 함수 매개 변수도 픽셀 단위입니다. 장치에서 UI를 사용하려면 픽셀을 사용하는 경우 고해상도 화면에서 UI가 너무 작아집니다.

는 픽셀 (DP)와는

플로트 heightInPixel = getHeight() /의 GetResources()로 변환하는 getDisplayMetrics()를 밀도..;