출처: http://johnfeng.github.io/blog/2015/10/12/android-relativelayouts-bug-for-devices-api-lower-than-17/
Problem
This afternoon, When I am implementing a simple ListView's item view, I found a really wired problem.
First, the layout is shown below:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
|
The problem is : when runs on devices with API over 18, the LinearLayout shown in right places. But when runs on below 17,
all padding properties of the LinearLayout seem do not work at all, with all subviews just shown at left-top side without
any space to bounds.
Fix
After long time searching , I found a piece of words on developer.android.com , which says:
Note: In platform version 17 and lower, RelativeLayout was affected by a measurement bug that could cause child views to be measured with incorrect MeasureSpec values. (See MeasureSpec.makeMeasureSpec for more details.)
This was triggered when a RelativeLayout container was placed in a scrolling container, such as a ScrollView
or HorizontalScrollView. If a custom view not equipped to properly measure with the MeasureSpec mode
UNSPECIFIED was placed in a RelativeLayout, this would silently work anyway as RelativeLayout would pass
a very large AT_MOST MeasureSpec instead.
And something more is:
It seems that this bug only affects RelativeLayout's child views, when RelativeLayout is inside of a scrolling container,
like a listview I am using. Thus , the result is quite simple , all measuring properties of RelativeLayout's child views should
best move to RelativeLayout itself. Like my list item , it should be like:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
|
all paddings have been moved into RelativeLayout from LinearLayout.
P.S. If your apps' lowest support API levels are above 18, you don't have to worry about this problem.
Peace!
'IT_Programming > Android_Java' 카테고리의 다른 글
[Admob] Admob 배치시 Required XML attribute "adSize"was missing 오류 발생 (0) | 2016.08.16 |
---|---|
Android WebView 예제 (0) | 2016.08.16 |
더 많은 사용자를 위한 앱 개발 (0) | 2016.08.15 |
[펌_번역] VectorDrawable 대응 정리 (0) | 2016.08.11 |
[펌] Android N - 멀티윈도우 지원 (0) | 2016.08.04 |