简体   繁体   中英

How to put a TextView resize depending on the resolution of Android

I have a problem here , i just getting starter with android Development , i was just in Windows Phone , and when i put in WP some TextView in my screen , he will be the same way in other screens , but in android is not .I want to know if have some code in XML who i can define the position and not change! Here is my XML

<RelativeLayout 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" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".Home"
android:background="@drawable/background">

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Recife +"
    android:textSize="40dp"
    android:textColor="@android:color/white"
    android:layout_marginTop="40dp"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:fontFamily=""
    android:id="@+id/textView" />
<TextView
    android:id="@+id/textView2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Horários, Rotas e Informações"
    android:textSize="25dp"
    android:textColor="@android:color/white"
    android:layout_marginTop="100dp"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"

    android:autoText="false" />
<Button
    android:layout_width="100dp"
    android:layout_height="100dp"
    android:layout_marginTop="250dp"
    android:background="@drawable/trem"
    android:id="@+id/butaoMetro"
    />

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="New Button"
    android:id="@+id/button"
    android:layout_below="@+id/butaoMetro"
    android:layout_alignEnd="@+id/textView" />

How can i fix this?thanks! 这里

I think this library autofit-textview can help you.

But you will need to wrap it into a custom FrameLayout nammed AutiFitLayout. Take a look at the example.

The problem here is android:textSize="25dp" set fixed for any resolution devices. For proper display you need to create layout for various resolution devices. For this you need to create different layout folder for different resolution devices and match according to it. Hope this helps 在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM