我正在尝试使用noman zoomtextview库为textview创建一个带滚动和缩放的应用程序。我导入项目时工作正常。我添加了一个活动,并将完全相同的代码从源项目活动复制到此活动。现在应用程序崩溃了。源项目java文件名为ZoomTextView.java和activity_main.xml
one.java文件:
'(?:name\s+of\s+)(\w+)'
one.xml文件:
package noman.zoomtextview;
import android.content.Context;
import android.support.annotation.NonNull;
import android.util.AttributeSet;
import android.util.Log;
import android.util.TypedValue;
import android.view.MotionEvent;
import android.view.ScaleGestureDetector;
import android.widget.TextView;
public class one extends TextView {
private static final String TAG = "ZoomTextView";
private ScaleGestureDetector mScaleDetector;
private float mScaleFactor = 1.f;
private float defaultSize;
private float zoomLimit = 3.0f;
public one(Context context) {
super(context);
initialize();
}
public one(Context context, AttributeSet attrs) {
super(context, attrs);
initialize();
}
public one(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
initialize();
}
private void initialize() {
defaultSize = getTextSize();
mScaleDetector = new ScaleGestureDetector(getContext(), new ScaleListener());
}
public void setZoomLimit(float zoomLimit) {
this.zoomLimit = zoomLimit;
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
@Override
public boolean onTouchEvent(@NonNull MotionEvent ev) {
super.onTouchEvent(ev);
mScaleDetector.onTouchEvent(ev);
return true;
}
private class ScaleListener extends ScaleGestureDetector.SimpleOnScaleGestureListener {
@Override
public boolean onScale(ScaleGestureDetector detector) {
mScaleFactor *= detector.getScaleFactor();
mScaleFactor = Math.max(1.0f, Math.min(mScaleFactor, zoomLimit));
setTextSize(TypedValue.COMPLEX_UNIT_PX, defaultSize * mScaleFactor);
Log.e(TAG, String.valueOf(mScaleFactor));
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"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin">
<noman.zoomtextview.ZoomTextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="@string/twentyfive" />
</RelativeLayout>
答案 0 :(得分:0)
您必须将新活动添加到您的清单。
这就是你必须的方式
<activity android:name=".YourNewActivity"/>
如果您的主要活动是您的新活动,那么请替换此
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
与
<activity android:name=".YourNewActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>