Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. <LinearLayout
  2. android:id="@+id/A"
  3. android:layout_height="fill_parent"
  4. android:layout_width="fill_parent"
  5. android:weightSum="8.0"
  6. android:orientation="vertical">
  7. <LinearLayout
  8. android:id="@+id/B"
  9. android:layout_height="0dip"
  10. android:layout_width="fill_parent"
  11. android:layout_weight="1.0"/>
  12. <LinearLayout
  13. android:id="@+id/C"
  14. android:layout_height="0dip"
  15. android:layout_width="fill_parent"
  16. android:layout_weight="3.0"
  17. </LinearLayout>
  18.  
  19. Context context;
  20.  
  21. @Override
  22. public void onAttach(Activity activity){
  23. super.onAttach(activity);
  24.  
  25. context = activity;
  26.  
  27.  
  28. }
  29.  
  30. public View onCreateView(LayoutInflater inflater, ViewGroup container,
  31. Bundle savedInstanceState) {
  32. Display display = ((WindowManager)
  33. context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
  34. DisplayMetrics metrics = new DisplayMetrics();
  35. display.getMetrics(metrics);
  36.  
  37. float pixHeight = metrics.heightPixels;
  38. float pixWidth = metrics.widthPixels;
  39. float density = context.getResources().getDisplayMetrics().density;
  40. float dpHeight = pixHeight / density;
  41. float dpWidth = pixWidth / density;
  42.  
  43. // make various layouts using your measurements, send the
  44. // measure of each parent to each custom drawn child, or
  45. // send the bounds of each child as determined by the size of each parent
  46.  
  47. return someView;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement