Android dividing a little part of screen vertically -
i have 2 images next each other.
sure using "dp" size, in screens images become little , in screens not. it's dp does.
i don't know must set sizes. 50dp, 75dp or 100dp... , don't know how decide that.
i want give images' size "screen size / 2" (because have 2 images) , want them scale sizes. mustn't give height. in resolution, must set width "screen width / 2" , height proportional width.
here graphic of want:
what should do?
any suggestions appreciated.
if want set images width screen size / 2
, make sure using px
instead of dp
, otherwise result different on various devices due resolution of devices. can width in pixels below code.
displaymetrics dm = new displaymetrics(); getwindowmanager().getdefaultdisplay().getmetrics(dm); displaywidth = dm.widthpixels;
after can set image width using one.
image_view.getlayoutparams().width = displaywidth /2;
hope solve problem.
the other way achieve make changes in .xml file this
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:weightsum="2" android:orientation="horizontal" > <imageview android:layout_width="0dp" android:layout_weight="1" ...... ........./> <imageview android:layout_width="0dp" android:layout_weight="1" ...... ........./> </linearlayout>
Comments
Post a Comment