0

I am working on a Android app with navigation drawer. I am using FrameLayout in my HomeFragment.xml. Inside the frame layout I want to use 3 text views and wish to align it vertically and horizontally such that alignment works for all screen sizes. Can any one help with this?

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
   xmlns:tools="http://schemas.android.com/tools"
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   tools:context="com.example.mgdetector.HomeFragment">


<TextView
    android:text="TextView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/absolute_strength"
    android:layout_marginTop="50dp"
    android:layout_marginLeft="10dp"
    android:layout_marginRight="10dp"
    android:textStyle="bold"
    android:textSize="@dimen/textsize"
    />

<TextView
    android:text=""
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/current_location_latitude"
    android:layout_marginTop="150dp"
    android:layout_marginLeft="10dp"
    android:layout_marginRight="10dp"
    android:textStyle="bold"
    android:textSize="@dimen/textsize"
    />

<TextView
    android:text=""
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/current_location_longitude"
    android:layout_marginTop="250dp"
    android:layout_marginLeft="10dp"
    android:layout_marginRight="10dp"

    android:textStyle="bold"
    android:textSize="@dimen/textsize"
    />
<Button
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom"
    android:id="@+id/stopButton"
    android:text="WARNING"
    android:visibility="gone"
    />

Currently I am using

android:layout_marginTop="250dp"  // with a difference of 100dp for TextView
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"

but I am not sure if this should work for screen sizes of different mobiles.

Bradley Wilson
  • 1,197
  • 1
  • 13
  • 26
ysg7790
  • 33
  • 5

1 Answers1

0

you should look this https://stackoverflow.com/a/21972021/3000053 and this link https://developer.android.com/guide/practices/screens_support.html

Community
  • 1
  • 1
caliskan
  • 107
  • 1
  • 6