本文介绍了捏缩放,TextView的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图创建一个显示的歌词,为用户的应用程序。歌词被存储的值/ strings.xml中内和访问活动时,为用户显示。 (我不知道这是否是做的好方法)。

I'm trying to create an app which displays lyrics for the user. The lyrics are stored within values/strings.xml and displayed for the user when accessing the activity. (I'm not sure if this is a good way of doing it).

根据文本的每一行有多长我不知道这TEXTSIZE我应该使用,我真的是想能够用一些捏缩放功能。

Depending on how long each line of text is I dont know which textsize I should use and I would really be able to use some "pinch to zoom" function.

不过,我不知道是否有可能捏,以放大对textviews。香港专业教育学院发现,这样做对网页视图和imageviews但没有对textviews的各种方法。

However, I dont know if it is possible "pinch" to zoom on textviews. Ive found various methods of doing it on webviews and imageviews but none for textviews.

我在寻找增加TEXTSIZE /由捏

I'm looking for the best way of increasing textsize/zooming the layout by "pinch"

帮助与如何存储字符串和显示是非常受欢迎的为好。

Help with how to store the strings and displaying is very welcome as well.

干杯!

推荐答案

我是新Android开发,并试图找出相同。我的测试应用程序在滚动型带双指缩放,但这一问题的工作要求在

I am new to Android development and have tried to figure out the same. I have test application working with pinch zoom but with the issue asked at TextView in a ScrollView with pinch zoom

这不过是工作

package com.example.pinchzoom;

import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
import android.util.TypedValue;
import android.view.Menu;
import android.view.MotionEvent;
import android.view.ScaleGestureDetector;
import android.view.ScaleGestureDetector.SimpleOnScaleGestureListener;
import android.widget.TextView;

public class MainActivity extends Activity {

    TextView scaleGesture;
    ScaleGestureDetector scaleGestureDetector;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        scaleGesture = (TextView)findViewById(R.id.article);
        scaleGesture.setText("this is some text");
        scaleGestureDetector = new ScaleGestureDetector(this, new simpleOnScaleGestureListener());
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }


    @Override
    public boolean onTouchEvent(MotionEvent event) {
        // TODO Auto-generated method stub
        scaleGestureDetector.onTouchEvent(event);
        return true;
    }

    public class simpleOnScaleGestureListener extends
            SimpleOnScaleGestureListener {

        @Override
        public boolean onScale(ScaleGestureDetector detector) {
            // TODO Auto-generated method stub
            float size = scaleGesture.getTextSize();
            Log.d("TextSizeStart", String.valueOf(size));

            float factor = detector.getScaleFactor();
            Log.d("Factor", String.valueOf(factor));


            float product = size*factor;
            Log.d("TextSize", String.valueOf(product));
            scaleGesture.setTextSize(TypedValue.COMPLEX_UNIT_PX, product);

            size = scaleGesture.getTextSize();
            Log.d("TextSizeEnd", String.valueOf(size));
            return true;
        }
    }
}

视图

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity" >
    <TextView
        android:id="@+id/article"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
</RelativeLayout>

这篇关于捏缩放,TextView的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 05:11