Java 放大“;TextView";资源文件中的文本文件

Java 放大“;TextView";资源文件中的文本文件,java,android,Java,Android,我正在开发图书应用程序。我想在文本文件上添加缩放功能。这是我的代码: 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" andr

我正在开发图书应用程序。我想在文本文件上添加缩放功能。这是我的代码:

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>

请提供一些帮助,

只需添加两个按钮:加号和减号

加上:

减:

    count = count -1;

    textView.setTextSize(count );

您可以使用以下代码在android://中对Textview进行压缩缩放,获取以下xml(布局)文件:


可能重复感谢,但我想从我的资源文件夹应用文本文件缩放。在这里提问之前我试过这个,但没用。
    count = count +1;
    count = count -1;

    textView.setTextSize(count );
<?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/mytv"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:text="
            This is my sample text for pinch zoom demo, you can zoom in and out using pinch zoom, thanks
            This is my sample text for pinch zoom demo, you can zoom in and out using pinch zoom, thanks
            This is my sample text for pinch zoom demo, you can zoom in and out using pinch zoom, thanks
            This is my sample text for pinch zoom demo, you can zoom in and out using pinch zoom, thanks
            This is my sample text for pinch zoom demo, you can zoom in and out using pinch zoom, thanks
            This is my sample text for pinch zoom demo, you can zoom in and out using pinch zoom, thanks

            This is my sample text for pinch zoom demo, you can zoom in and out using pinch zoom, thanks
            This is my sample text for pinch zoom demo, you can zoom in and out using pinch zoom, thanks
            This is my sample text for pinch zoom demo, you can zoom in and out using pinch zoom, thanks
            This is my sample text for pinch zoom demo, you can zoom in and out using pinch zoom, thanks
            This is my sample text for pinch zoom demo, you can zoom in and out using pinch zoom, thanks
            This is my sample text for pinch zoom demo, you can zoom in and out using pinch zoom, thanks
            " />

    </RelativeLayout>
public class MyTextViewPinchZoomClass extends Activity implements OnTouchListener {

    final static float STEP = 200;
    TextView mytv;
    float mRatio = 1.0f;
    int mBaseDist;
    float mBaseRatio;
    float fontsize = 13;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.layout_file_name_here);

        mytv = (TextView) findViewById(R.id.mytv);
        mytv.setTextSize(mRatio + 13);
    }

    public boolean onTouchEvent(MotionEvent event) {
        if (event.getPointerCount() == 2) {
            int action = event.getAction();
            int pureaction = action & MotionEvent.ACTION_MASK;
            if (pureaction == MotionEvent.ACTION_POINTER_DOWN) {
                mBaseDist = getDistance(event);
                mBaseRatio = mRatio;
            } else {
                float delta = (getDistance(event) - mBaseDist) / STEP;
                float multi = (float) Math.pow(2, delta);
                mRatio = Math.min(1024.0f, Math.max(0.1f, mBaseRatio * multi));
                mytv.setTextSize(mRatio + 13);
            }
        }
        return true;
    }

    int getDistance(MotionEvent event) {
        int dx = (int) (event.getX(0) - event.getX(1));
        int dy = (int) (event.getY(0) - event.getY(1));
        return (int) (Math.sqrt(dx * dx + dy * dy));
    }

    public boolean onTouch(View v, MotionEvent event) {
        return false;
    }
}