To set an image to fill 50% of the screen on all Android devices, what size of image should I keep in a resource folder?
get the screen size of device and set the image height screenheight/2
get height by this code
- DisplayMetrics displayMetrics = new DisplayMetrics();
- getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
- int height = displayMetrics.heightPixels;
- int width = displayMetrics.widthPixels;
or do something like this in xml code
- android:orientation="vertical"
- android:layout_width="match_parent"
- android:layout_height="match_parent">
- android:layout_width="match_parent"
- android:layout_height="0dp"
- android:layout_weight="0.5"
- android:background="#ff0000"
- >
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:src="@drawable/your_image"
- android:adjustViewBounds="true"
- />
- android:layout_width="match_parent"
- android:layout_height="0dp"
- android:layout_weight="0.5"
- android:background="#00ff00"
- />
Artigos semelhantes
- How to set the default paper size in Google Docs
- What is the best mid-range phone with a screen size of 5 to 5.5 inches?
- How to detect an object from static image and crop it from the image using openCV
- Which one should I buy: the Moto X Style, Xperia M5, Google Nexus 5 (2015), or should I wait for any other phone in these phones' price range?