QNA > T > 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?

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

  1. DisplayMetrics displayMetrics = new DisplayMetrics(); 
  2. getWindowManager().getDefaultDisplay().getMetrics(displayMetrics); 
  3. int height = displayMetrics.heightPixels; 
  4. int width = displayMetrics.widthPixels; 

or do something like this in xml code

  1. android:orientation="vertical" 
  2. android:layout_width="match_parent" 
  3. android:layout_height="match_parent"> 
  4. android:layout_width="match_parent" 
  5. android:layout_height="0dp" 
  6. android:layout_weight="0.5" 
  7. android:background="#ff0000" 
  8. android:layout_width="match_parent" 
  9. android:layout_height="match_parent" 
  10. android:src="@drawable/your_image" 
  11. android:adjustViewBounds="true" 
  12. /> 
  13.  
  14. android:layout_width="match_parent" 
  15. android:layout_height="0dp" 
  16. android:layout_weight="0.5" 
  17. android:background="#00ff00" 
  18. /> 
  19.  

Di Lamoree

Qual è la differenza tra am/is/are + yet to e has/have + yet to? :: Dovrei comprare ZTE axon m?
Link utili