Advertisement
Guest User

Untitled

a guest
Apr 21st, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.47 KB | None | 0 0
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. xmlns:tools="http://schemas.android.com/tools"
  4. android:layout_width="match_parent"
  5. android:layout_height="match_parent"
  6. tools:context="com.example.manos.videoviewmetrics.MainActivity">
  7.  
  8. <RelativeLayout
  9. android:layout_alignParentTop="true"
  10. android:id="@+id/topLayout"
  11. android:layout_width="wrap_content"
  12. android:layout_height="wrap_content">
  13.  
  14. <ImageView
  15. android:layout_centerVertical="true"
  16. android:layout_centerHorizontal="true"
  17. android:background="@mipmap/ic_wallpaper1"
  18. android:id="@+id/imageView1"
  19. android:layout_width="1920dp"
  20. android:layout_height="1080dp" />
  21.  
  22. </RelativeLayout>
  23.  
  24. <RelativeLayout
  25. android:id="@+id/bottomLayout"
  26. android:layout_width="match_parent"
  27. android:layout_height="wrap_content"
  28. android:layout_below="@+id/topLayout">
  29.  
  30. <ImageView
  31. android:background="@mipmap/ic_wallpaper2"
  32. android:id="@+id/imageView2"
  33. android:layout_width="1280dp"
  34. android:layout_height="720dp" />
  35.  
  36. </RelativeLayout>
  37.  
  38.  
  39. </RelativeLayout>
  40.  
  41. public class MainActivity extends AppCompatActivity {
  42.  
  43. private RelativeLayout topLayout, bottomLayout;
  44. private ImageView topImageView, bottomImageView;
  45.  
  46. @Override
  47. protected void onCreate(Bundle savedInstanceState) {
  48. super.onCreate(savedInstanceState);
  49. setContentView(R.layout.activity_main);
  50.  
  51. topLayout = (RelativeLayout) findViewById(R.id.topLayout);
  52. bottomLayout = (RelativeLayout) findViewById(R.id.bottomLayout);
  53. topImageView = (ImageView) findViewById(R.id.imageView1);
  54. bottomImageView = (ImageView) findViewById(R.id.imageView2);
  55.  
  56.  
  57. DisplayMetrics displaymetrics = new DisplayMetrics();
  58. getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
  59.  
  60. int wantedHeight = displaymetrics.heightPixels / 2;
  61. //int wantedWidth = displaymetrics.widthPixels;
  62.  
  63. int currentHeight = 1080;
  64. int currentWidth = 1920;
  65.  
  66.  
  67. float scaleFactor = (float) wantedHeight/ (float) currentHeight ;
  68.  
  69. int newWidth = (int) (scaleFactor * currentWidth);
  70. int newHeight = (int) (scaleFactor * currentHeight);
  71.  
  72. topLayout.getLayoutParams().height = newHeight;
  73. topLayout.getLayoutParams().width = newWidth;
  74. }
  75.  
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement