Reputation: 47
Help to understand please.
I need to show up in a specific box.
I do it like this:
<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:background="@drawable/fon"
tools:context=".MainActivity" >
....
<TextView
android:id="@+id/textView3"
android:layout_width="200dp"
android:layout_height="210dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:includeFontPadding="false"
android:lineSpacingMultiplier="0.8"
android:textAlignment="center"
android:textColor="@color/black"
android:textSize="20sp" />
....
</RelativeLayout>
Everything works at four inch screen well but if take a big diagonal, it will be bad.
At increase in the screen the textView size doesn't change.
I use "dp" and "sp", instead of static "px", but does not work...
Why Is this happening ?
screenshots:
Upvotes: 0
Views: 149
Reputation: 1210
You can create different resource directories for different screen sizes and densities and then create dimens.xml
in each of them providing text size to be used on specific screen size, for example:
res/values-sw420dp/dimens.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="font_size">26sp</dimen>
</resources>
res/values-sw600dp/dimens.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="font_size">30sp</dimen>
</resources>
res/values-sw720dp/dimens.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="font_size">36sp</dimen>
</resources>
And then call it in your layout file:
android:textSize="@dimen/font_size"
This is a solution for the text size, but you can do the same thing for width and height.
More resources:
Upvotes: 1
Reputation: 207
You should adjust the TextView android:layout_width and android:layout_height to
android:layout_width="wrap_content"
android:layout_height="wrap_content"
If you want the TextView to center inside the white background, you should add another attribute
android:layout_centerInParent="true"
Upvotes: 0
Reputation: 1039
The text view size is static because you have defined a fixed size to them.Use wrap content.
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Upvotes: 0