Reputation: 110
I have a table layout with textviews in 2 columns (see xml below). On small screens the text fills almost all the space and it looks fine. But on bigger screens there is a lot of unused space left (and what is worse, there is a gap between the left and the right column).
What is the best way to make the text increase in size when more screen width is available (especially in landscape orientation). Maybe it can be done automatically?
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:ads="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/mainLayout"
android:background="#E0F9FF"
tools:context=".MainActivity"
android:orientation="vertical">
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scrollbars="vertical"
android:layout_weight="1">
<TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="12dp"
android:id="@+id/tableLayout" >
<TableRow
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="@string/tbl_ipv4_ext"
android:id="@+id/textView"
android:layout_column="0"
android:layout_weight="6"
android:paddingBottom="10dp"
android:paddingLeft="6dp"
android:textStyle="bold|italic" />
<TextView
android:textIsSelectable="true"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="@string/tbl_no_connection"
android:id="@+id/textView2"
android:layout_column="10"
android:layout_weight="9"
android:textStyle="bold"/>
</TableRow>
<...many similar table rows...>
</TableLayout>
</ScrollView>
<com.google.android.gms.ads.AdView android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
ads:adSize="SMART_BANNER"
ads:adUnitId="bla-bla-bla" />
Upvotes: 0
Views: 4054
Reputation: 4123
1- Import android support library 26.x.x on your project gradle file. If there is no support library on IDE, they will download automatically.
dependencies {
compile 'com.android.support:support-v4:26.1.0'
compile 'com.android.support:appcompat-v7:26.1.0'
compile 'com.android.support:support-v13:26.1.0'
}
allprojects {
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
}
}
2- Open your layout XML file and refactor like this tag your TextView. This scenario is: when increased font size on the system, fit text to available width, not word wrap.
<android.support.v7.widget.AppCompatTextView
android:id="@+id/textViewAutoSize"
android:layout_width="match_parent"
android:layout_height="25dp"
android:ellipsize="none"
android:text="Auto size text with compatible lower android versions."
android:textSize="12sp"
app:autoSizeMaxTextSize="14sp"
app:autoSizeMinTextSize="4sp"
app:autoSizeStepGranularity="0.5sp"
app:autoSizeTextType="uniform" />
Upvotes: 0
Reputation: 186
You can use StaticLayout and calculate optimal font size for your width or take some lib with autofitTextView, for example: https://github.com/AndroidDeveloperLB/AutoFitTextView
Upvotes: 1