Inconsistent layout_weight in simulator vs Android Studio renderer -


below see xml code , screenshot.
summary:

  • one parent linearlayout weightsum = 100
  • one child linearlayout layout_weight = 25
  • one child linearlayout layout_weight = 75

result:

  • in android studio layout renderer children ratio ok (25:75)
  • in simulator ratio between children not ok (clearly not 25:75)

    <?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android"     android:orientation="vertical"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:weightsum="100">      <linearlayout         android:background="@color/md_orange_600"         android:orientation="vertical"         android:layout_width="match_parent"         android:layout_height="0dp"         android:layout_weight="25"         android:layout_gravity="center_horizontal">     </linearlayout>      <linearlayout         android:orientation="vertical"         android:layout_width="match_parent"         android:layout_height="0dp"         android:layout_gravity="center_horizontal"         android:layout_margin="@dimen/default_separator"         android:background="@color/md_green_400"         android:layout_weight="75">     </linearlayout>  </linearlayout> 

resulting screenshot

some notes:

  • the layout_height 0dp on both children (as recommended weights)
  • i colored background area assignment visible

found root problem:

it turns out main activiy layout has coordinatorlayout primary container.

coordinatorlayout children placement framelayout, therefore appbarlayout , main fragment container (framelayout) overlapped. enclosed them both vertical oriented linearlayout , don't overlap.

corollary, 2 cents developers out there: tempting bypass problems without understanding real cause (i have add layout_margintop on fragment "shift down") in end, bypass after bypass end understanding less , less of own application. understand real cause of problem experience, solution real too.


Comments

Popular posts from this blog

routing - AngularJS State management ->load multiple states in one page -

python - GRASS parser() error -

Swift game error message -