0

What is the best way to draw a perfect layout that could adapts in every device without problems of density/resolution ?

I used buckets (layout-120dpi,layout-160dpi,layout-240dpi,layout-320dpi,layout-480dpi,layout-120dpi). It is correct? I will have problems? If yes what kind of problem and with such devices? Thanks in advance

layout example :

enter image description here enter image description here enter image description here

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:text="This is a title"
    android:id="@+id/nick"
    android:layout_gravity="center_horizontal"
    android:textColor="#ff000000"
    android:layout_marginTop="15dp"
    android:textSize="25sp" />

<ImageView
    android:layout_width="270dp"
    android:layout_height="270dp"
    android:id="@+id/photo"
    android:background="#ffff0000"
    android:layout_gravity="center_horizontal"
    android:layout_marginTop="25dp" />

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:text="StackOverflowStackOverflowStackOverflowStackOverflowStackOverflowStackOverflowStackOverflowStackOverflow"
    android:id="@+id/state"
    android:textColor="#ff000000"
    android:layout_marginRight="10dp"
    android:layout_marginLeft="10dp"
    android:layout_marginTop="22dp" />
ClearCode
  • 47
  • 4
  • 11
  • 1
    Layouts usually do not vary by screen density. IMHO, using densities for anything other than drawable resources is a code smell. Beyond that, you may wish to edit your question with your actual code and an explanation of the actual problems that you are experiencing. – CommonsWare Feb 28 '15 at 21:42
  • @CommonsWare any kind of issues but when I tried for the first time to create a layout I had a lot of problem with scale. Now I am developing this app with these buckets. I would know how app developers create their layout, if they use dpi buckets, code or something else. In my brain there is a lot of confusion about what influences a layout (dpi/dp/px). – ClearCode Feb 28 '15 at 21:48
  • "when I tried for the first time to create a layout I had a lot of problem with scale" -- then perhaps you might want to ask a Stack Overflow question where you provide your layout and you explain what your "problem with scale" is. – CommonsWare Feb 28 '15 at 21:52
  • For example I have blank spaces in some parts of layout, maybe with a more accurate realization I could fix these "problems" – ClearCode Feb 28 '15 at 21:52
  • @CommonsWare post edited. As you can see with different devices my layout changes, this is ok but I would avoid that in the first device text is in bottom. This is caused by the different resolution/density I think. I want my layout look likes the same in every device – ClearCode Feb 28 '15 at 22:00
  • "As you can see with different devices my layout changes" -- that looks to be the same layout in all three cases. However, since you decided not to provide the layout XML and how you are using that XML, it will be difficult for anyone to help you. "I would avoid that in the first device text is in bottom" -- feel free to explain where you would like the text. "This is caused by the different resolution/density I think" -- it is not caused by different density. Resolution and density are not the same thing. – CommonsWare Feb 28 '15 at 22:05
  • @CommonsWare code posted. I would know how my layout can change everything to allow the text to be the same in every device. You can see that in the first device text end to the end of display, in the others devices there is a blank space, so I want do the same in every device. – ClearCode Feb 28 '15 at 22:14
  • That is not a complete layout file. At this point, I am tired of trying to pull complete and accurate information out of you. Perhaps somebody else will elect to help you, or perhaps you might try [other sites](http://www.andglobe.com). – CommonsWare Feb 28 '15 at 22:22

0 Answers0