0

I have a constraint layout that cannot scroll, all the views have to be visible all the time. The problem that I have is that with devices of height 1920 or less, the UI gets really crowded and some text views start overlapping, bottom gets cut off a little.

Layout structure is

<ConstraintLayout>
  <LinearLayout />
  <FrameLayout /> <-- this has an imageview of fixed height of 192dp
  <some views..>
  <last view> <-- has app:layout_constraintBottom_toBottomOf="parent" constraint
</ConstraintLayout>

How do I say height 1920 or below use a different layout? I tried some qualifiers such as sw320dp, layout-h1920dp (not a good choice) on Nexus 5 but it doesn't pickup the layout from those directories. How do I handle Nexus 5 in this case?

I don't think measuring the height and doing a dynamic layout is an attractive option.

1 Answer 1

1

You can't do size<y use a different layout, but you can do size >x use a different layout. So do that. Put the small sized layout in your layouts directory, and your big layout in the layout-h1920dp.

BTW, 1920dp is huge. That's 12 inches in height alone (160dp=1 inch)- basically you'd be looking at a monitor. Even the biggest tablets only have 12 inch diagonals, and that's a tiny number- most are 7 or 10 inch. I doubt there's any model on the market that big. So 1920 dp is not the size you're going to want.

Sign up to request clarification or add additional context in comments.

4 Comments

sorry I may have mentioned it wrong, 1920 is pixel size (Nexus 5) and not 1920dp if I understood correctly. The device where I am seeing views being squished is Nexus %
@rysv So swxxx the xxx is in dp, not pixels. It's highly recommended that you never use pixels in your layouts, and only do it when using Canvas drawing or onMeasure/onLayout of a custom view where it's necessary.
Basically, the question is - how to differentiate devices, for example, that has a height of 1920 pixels (Nexus 5, UI messed up) vs a height of 2340 pixels (Google Pixel 5, UI is ok). My theory is if I can differentiate using resource qualifiers I can create a separate layout. If not, I have to try app:layout_constraintHeight_percent maybe? I understand I should not use pixels but trying to figure out the way this is addressed usually.
There's several ways depending on what effect you actually want. Why do you think this view should be 1920 pixels? What are you actually trying to do? Does it have content that fits a certain physical size? If so, figure out what that size is physically and convert it to dp, and use layout-hXXXdp directories. If you want the view to take up a certain percent of your screen and no more, then a percent constraint is appropriate. If you think it should be 1920 pixels because the image is 1920 pixels- you want to decide on either a percentage or physical size instead and scale the image

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.