How can I make the Text Size adapt to different sized devices/linear layouts in Android -


i working on layout file adjusts android devices of different sizes. far have had success. using "layout_weight" have been able make linear layout take percentage of space in layout. means display can stretched cover whole screen weather on 2'7 inch screen or 10'1 inch screen. however, having problems text size in linear layout @ top. how can make textsize adapt big or small devices? here code.

 <?xml version="1.0" encoding="utf-8"?>       <linearlayout xmlns:android="http://schemas.android.com/apk/res/android"           android:orientation="vertical"           android:layout_width="fill_parent"           android:layout_height="fill_parent"           android:baselinealigned="false"           android:weightsum="1.0"           android:background="#ff0000"           >       <linearlayout           android:orientation="horizontal"           android:layout_width="fill_parent"           android:layout_height="0dip"           android:layout_weight="0.25"           android:weightsum="1.0">       <textview         android:id="@+id/textview1"          android:layout_width="fill_parent"         android:layout_height="wrap_content"         android:text="medium"         android:textsize="30sp"         android:layout_weight="1"          android:textappearance="?android:attr/textappearancelarge" />       </linearlayout>       <linearlayout           android:orientation="horizontal"           android:layout_width="fill_parent"           android:layout_height="0dip"           android:layout_weight="0.25"           android:weightsum="1.0">                  <imageview              android:layout_width="0dip"             android:layout_height="fill_parent"             android:src="@drawable/sample_1"             android:layout_gravity="center_horizontal"             android:layout_weight="0.25"         />          <imageview              android:layout_width="0dip"             android:layout_height="fill_parent"             android:src="@drawable/sample_2"             android:layout_gravity="center_horizontal"             android:layout_weight="0.25"         />          <imageview              android:layout_width="0dip"             android:layout_height="fill_parent"             android:src="@drawable/sample_3"             android:layout_gravity="center_horizontal"             android:layout_weight="0.25"         />          <imageview              android:layout_width="0dip"             android:layout_height="fill_parent"             android:src="@drawable/sample_4"             android:layout_gravity="center_horizontal"             android:layout_weight="0.25"         />      </linearlayout>       <linearlayout          android:orientation="horizontal"          android:layout_width="fill_parent"          android:layout_height="0dip"          android:layout_weight="0.25"          android:weightsum="1.0">                    <imageview                 android:layout_width="0dip"                android:layout_height="fill_parent"                android:src="@drawable/sample_1"                android:layout_gravity="center_horizontal"                android:layout_weight="0.25"            />          <imageview              android:layout_width="0dip"             android:layout_height="fill_parent"             android:src="@drawable/sample_2"             android:layout_gravity="center_horizontal"             android:layout_weight="0.25"         />          <imageview              android:layout_width="0dip"             android:layout_height="fill_parent"             android:src="@drawable/sample_3"             android:layout_gravity="center_horizontal"             android:layout_weight="0.25"         />          <imageview              android:layout_width="0dip"             android:layout_height="fill_parent"             android:src="@drawable/sample_4"             android:layout_gravity="center_horizontal"             android:layout_weight="0.25"         />      </linearlayout>      <linearlayout       android:orientation="horizontal"       android:layout_width="fill_parent"       android:layout_height="0dip"       android:layout_weight="0.25"       android:weightsum="1.0">                 <imageview              android:layout_width="0dip"             android:layout_height="fill_parent"             android:src="@drawable/sample_1"             android:layout_gravity="center_horizontal"             android:layout_weight="0.25"         />          <imageview              android:layout_width="0dip"             android:layout_height="fill_parent"             android:src="@drawable/sample_2"             android:layout_gravity="center_horizontal"             android:layout_weight="0.25"         />          <imageview              android:layout_width="0dip"             android:layout_height="fill_parent"             android:src="@drawable/sample_3"             android:layout_gravity="center_horizontal"             android:layout_weight="0.25"         />          <imageview              android:layout_width="0dip"             android:layout_height="fill_parent"             android:src="@drawable/sample_4"             android:layout_gravity="center_horizontal"             android:layout_weight="0.25"                />       </linearlayout>       </linearlayout> 

inside res folder create different folders like values-ldpi, values-mdpi, values-hdpi, values-xhdpi

than inside these folders create dimens.xml file

should like

res/values-ldpi/dimens.xml res/values-mdpi/dimens.xml res/values-hdpi/dimens.xml 

than define different sizes textview inside dimens.xml


Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -