Reputation: 9138
I have a FrameLayout that is used to display a camera feed for scanning with ZBar.
I would like it to take up a large proportion of every screen the app runs on. A hardcoded 275dp square looks great on the latest phones but pushed stuff off when for smaller screens.
I am planning on hardcoding a 175dp square and then in code making it grow based on the dimensions of the phones screen.
I'll probably do a switch
on various screen sizes and then decide what to resize the frame to.
Is this a good approach?
How would I go about doing this in XML?
Upvotes: 0
Views: 108
Reputation: 508
You can make one xml layout file for ldpi, mdpi and hdpi(xhdpi and tvdpi if you want to) and literally set different xmls according to the screensize. With this you will be able to fit most screens without a problem, but it is not as accurate as percentage. But remember that not all android devices has the usual 16:9 or 16:10(8:5) and therefore percentage may make the square a bit different from screen to screen.
You can make your own layout qualifyers, but the standard ones are in most cases more then enough.
You should also consider makeing only the frame layout in java, and the rest of the layout in xml.
Upvotes: 0
Reputation: 46425
A LinearLayout
with layout_weight
specified for height/width will allow you to simulate a percentage based layout, otherwise you can use fill_parent
when you want to use the whole screen width/height.
Upvotes: 2