0

this is the picture with same text size on 5inch screen

this is the picture with same textsize on 4inch screen

I want the text in the Text View to fit on different screen sizes depending on their fonts. I have used html for the text.

Here's my strings.xml

<string name="seven">
<![CDATA[
<h1>श्रीज्ञानदेवाची आरती</h1>

<body>आरती ज्ञानराजा॥<br>
महाकैवल्यतेजा॥<br>
सेविती साधुसंत ॥<br>
मनु वेधला माझा ॥ ध्रु० ॥<br>
लोपलें ज्ञान जगीं ॥<br>
हित नेणती कोणी ॥<br>   
अवतार पांडुरंग ॥<br>
नाम ठेविलें ज्ञानी ॥ आरती ॥ १ ॥<br>
कनकांचे ताट करीं ॥<br>
उभ्या गोपिका नारी ॥<br>
नारद तुंबरु ही ॥<br>
साम गायन करी ॥ आरती० ॥ २ ॥<br>
प्रगट गुह्य बोले ॥<br>
विश्व ब्रह्मची केलें ॥<br>
रामा जनार्दनीं ॥<br>
चरणी मस्तक ठेविले ॥ आरती० ॥ ३ ॥<br>
<br>
<br>
<br></body>]]>

activity.xml

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:textAppearance="?android:attr/textAppearanceLarge"
android:id="@+id/textView15"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />

activity.java

tv15=(TextView)findViewById(R.id.textView15);
tv15.setTextSize((float)23.5);
tv15.setText(Html.fromHtml(getString(R.string.seven)));
halfer
  • 19,824
  • 17
  • 99
  • 186
Devk
  • 117
  • 11
  • what is problem you are facing ? – N J Jul 16 '16 at 05:49
  • the text gets properly fit on 5 inch screen.....whereas there is problem when put on 4inch screen phone.....the text in the text view does not fit on it....means some lines come on the next line..... – Devk Jul 16 '16 at 05:59
  • check the images N J – Devk Jul 16 '16 at 06:51
  • check this http://stackoverflow.com/questions/9884091/dynamic-text-size-change-according-to-tablet this may help you – N J Jul 16 '16 at 06:57

2 Answers2

0

Following way may helps you.

Define some size in dimens.xml

<dimen name="textSize">15sp</dimen>

then in Java, setTextSize like,

int txtsize = getResources().getDimensionPixelSize(R.textSize);
tv15.setTextSize(txtsize);

this will give same sizes of all devices.

Sathish Kumar J
  • 4,280
  • 1
  • 20
  • 48
  • that doesnt solve my question......the problem is that the text gets properly fit on 5 inch screen.....whereas there is problem when put on 4inch screen phone.....the text in the text view does not fit on it....means some lines come on the next line..... – Devk Jul 16 '16 at 06:34
  • kindly check the images Sathish Kumar J – Devk Jul 16 '16 at 06:51
  • refer this link may helps you http://stackoverflow.com/questions/9877946/text-size-and-different-android-screen-sizes – Sathish Kumar J Jul 16 '16 at 06:56
0

You have set fix pixel size here

tv15.setTextSize((float)23.5);

So it getting same size for all screen.

Solution1. Take text size in dp in xml

android:textSize="18dp"

Solution2. Take different dimention file for different screen size.

value-mdpi/dimen.xml
<dimen name="hindi_text_size">15dp</dimen>

value-hdpi/dimen.xml
<dimen name="hindi_text_size">18dp</dimen>

in xml now use this parameter

android:textSize="@dimen/hindi_text_size"

Jitendra
  • 3,608
  • 2
  • 17
  • 19