Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?xml version="1.0" encoding="utf-8"?>
- <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:tools="http://schemas.android.com/tools"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- tools:context="com.example.manos.videoviewmetrics.MainActivity">
- <RelativeLayout
- android:layout_alignParentTop="true"
- android:id="@+id/topLayout"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content">
- <ImageView
- android:layout_centerVertical="true"
- android:layout_centerHorizontal="true"
- android:background="@mipmap/ic_wallpaper1"
- android:id="@+id/imageView1"
- android:layout_width="1920dp"
- android:layout_height="1080dp" />
- </RelativeLayout>
- <RelativeLayout
- android:id="@+id/bottomLayout"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_below="@+id/topLayout">
- <ImageView
- android:background="@mipmap/ic_wallpaper2"
- android:id="@+id/imageView2"
- android:layout_width="1280dp"
- android:layout_height="720dp" />
- </RelativeLayout>
- </RelativeLayout>
- public class MainActivity extends AppCompatActivity {
- private RelativeLayout topLayout, bottomLayout;
- private ImageView topImageView, bottomImageView;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- topLayout = (RelativeLayout) findViewById(R.id.topLayout);
- bottomLayout = (RelativeLayout) findViewById(R.id.bottomLayout);
- topImageView = (ImageView) findViewById(R.id.imageView1);
- bottomImageView = (ImageView) findViewById(R.id.imageView2);
- DisplayMetrics displaymetrics = new DisplayMetrics();
- getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
- int wantedHeight = displaymetrics.heightPixels / 2;
- //int wantedWidth = displaymetrics.widthPixels;
- int currentHeight = 1080;
- int currentWidth = 1920;
- float scaleFactor = (float) wantedHeight/ (float) currentHeight ;
- int newWidth = (int) (scaleFactor * currentWidth);
- int newHeight = (int) (scaleFactor * currentHeight);
- topLayout.getLayoutParams().height = newHeight;
- topLayout.getLayoutParams().width = newWidth;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement