0

I have code that produces a countdown TextView to a specific date, I have positioned to the perfect position to use on my device, but when I use bigger or smaller screen sized devices the TextView moves out of position. How do I position it at the same position for all devices?

Here is my code:

<RelativeLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:components="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/newbackground"
android:orientation="vertical"
tools:context=".MainActivity">

<LinearLayout
    android:id="@+id/linear_layout"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:layout_marginBottom="70dp">

    <TextView
        android:id="@+id/countdown_text_view"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:fontFamily="sans-serif-thin"
        android:gravity="center_horizontal"
        android:textColor="#F44336"
        android:textSize="20sp"/>

pnuts
  • 58,317
  • 11
  • 87
  • 139
Declan Morgan
  • 309
  • 3
  • 12
  • Why do you mean exactly by move out of position? can you show a screenshot? – Virthuss Oct 02 '15 at 04:17
  • So, I have a background image for the app with a white box, I have positioned the TextView so that it appears inside this white box, but when i try it on other devices, the TextView moves either above or below the white box. – Declan Morgan Oct 02 '15 at 04:19
  • Is your textview suppose to remain on the middle of the screen, on a relative position ( like left or right center...), or is your whitebox in a custom position that you need to reach using specific measure? – Virthuss Oct 02 '15 at 04:22
  • so the whitebox is positioned on the image that is set as my background for the app. When i load it onto bigger devices for example, the size of the image resizes to meet the needs of the devices screen size, but the TextView does not move if that makes any more sense – Declan Morgan Oct 02 '15 at 04:29
  • I need to know where the whitebox is on the background exactly, I cant really help otherwhise ^^ – Virthuss Oct 02 '15 at 04:34
  • it's like at the bottom, centered – Declan Morgan Oct 02 '15 at 04:35
  • I think the problem is your margin bottom on LinaerLayout, the dp unit is independant but sometimes the screen ratio can change and then it doesn't fit anymore. What you can do is trying to get the height of your screen and programmatically set the margin of your layout according to this one. But the best idea would be to put your textview in an additionnal layout, and set this layout as your textbox instead of using a background if you can. – Virthuss Oct 02 '15 at 04:42
  • If your whitebox is stuck to the bottom directly, try using a different measur unit. see this link : http://stackoverflow.com/questions/2025282/difference-between-px-dp-dip-and-sp-in-android – Virthuss Oct 02 '15 at 04:43
  • That has helped a bit, not much though, I read a few other questions similar to this and some people said to use layout_weight, I have tried using this before but it didn't work properly? do you happen to know any good practices for using layout_weight – Declan Morgan Oct 02 '15 at 18:43
  • layout_weight is mainly used to spread elements in a layout according to the weight you will give them. If in a layout you have three element with a weight of 0.33 in a layout with a weight of 1, those three elements will take the same amount of space in the layout. Once again, a screenshot would help me to help you – Virthuss Oct 05 '15 at 03:21

0 Answers0