2015-02-07 154 views
0

我有一個表格佈局,其中包含2列textview(見下面的xml)。在小屏幕上,文字填滿了幾乎所有的空間,看起來很好。但是在更大的屏幕上還有很多未使用的空間(更糟糕的是,左側和右側列之間存在間隙)。textView自動填充寬度的文本

當更多的屏幕寬度可用時(特別是在橫向方向),使文本尺寸增大的最佳方式是什麼?也許它可以自動完成?

<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" /> 

回答

0

1導入機器人在你的項目支持庫26.xx gradle文件。如果IDE上沒有支持庫,它們將自動下載。

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-打開您的佈局XML文件並像這樣重構您的TextView。這種情況是:在系統上增加字體大小時,使文本適合可用寬度,而不是自動換行。

<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" />