我正在編寫書籍應用程序。我想在我的文本文件上添加縮放功能。在這裏我的代碼:從資源文件中放大文本文件中的「TextView」
XML文件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ScrollView
android:id="@+id/ScrollView01"
android:layout_width="fill_parent"
android:layout_height="match_parent" >
<TextView
android:id="@+id/textview_data"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Naruto"
android:textSize="25dp" />
</ScrollView>
</LinearLayout>
在MainActivity我申請一些MapView的縮放方法來解決這個問題,但這些方法並沒有太大幫助。
package com.example.readtextfiles;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.widget.TextView;
public class ReadTextFileActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView textView = (TextView)findViewById(R.id.textview_data);
String data = readTextFile(this, R.raw.books);
textView.setText(data);
}
public static String readTextFile(Context ctx, int resId)
{
InputStream inputStream = ctx.getResources().openRawResource(resId);
InputStreamReader inputreader = new InputStreamReader(inputStream);
BufferedReader bufferedreader = new BufferedReader(inputreader);
String line;
StringBuilder stringBuilder = new StringBuilder();
try
{
while ((line = bufferedreader.readLine()) != null)
{
stringBuilder.append(line);
stringBuilder.append('\n');
}
}
catch (IOException e)
{
return null;
}
return stringBuilder.toString();
}
}
請提出一些幫助,
可能重複([如何放大Android的一個TextView?] http://stackoverflow.com/questions/10239891/how-to-zoom-a-textview-in-android) – karvoynistas 2014-10-20 12:36:36