編輯:關於android開發
效果:字體縮放(無數倍),目前我自定義有個倍數,不過有點BUG;而且scroollveiw滑動沖突沒解決;
1. activity_main.xml
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="11sp"
android:scrollbars="vertical"
/>
</ScrollView>
2. MainActivity.java
TextView textView = (TextView) findViewById(R.id.textView);
textView.setMovementMethod(ScrollingMovementMethod.getInstance());
textView.setText("道德三皇五帝,\n" + "功名夏後商周.\n" + "英雄五霸鬧春秋,\n" + "頃刻興亡過手.\n"
+ "青史幾行名姓,\n" + "北邙無數荒丘.\n" + "前人田地後人收,\n" + "說甚龍爭虎斗." + "道德三皇五帝,\n" + "功名夏後商周.\n" + "英雄五霸鬧春秋,\n" + "頃刻興亡過手.\n"
+ "青史幾行名姓,\n" + "北邙無數荒丘.\n" + "前人田地後人收,\n" + "說甚龍爭虎斗." + "道德三皇五帝,\n" + "功名夏後商周.\n" + "英雄五霸鬧春秋,\n" + "頃刻興亡過手.\n"
+ "青史幾行名姓,\n" + "北邙無數荒丘.\n" + "前人田地後人收,\n" + "說甚龍爭虎斗." + "道德三皇五帝,\n" + "功名夏後商周.\n" + "英雄五霸鬧春秋,\n" + "頃刻興亡過手.\n"
+ "青史幾行名姓,\n" + "北邙無數荒丘.\n" + "前人田地後人收,\n" + "說甚龍爭虎斗." + "道德三皇五帝,\n" + "功名夏後商周.\n" + "英雄五霸鬧春秋,\n" + "頃刻興亡過手.\n"
+ "青史幾行名姓,\n" + "北邙無數荒丘.\n" + "前人田地後人收,\n" + "說甚龍爭虎斗." + "道德三皇五帝,\n" + "功名夏後商周.\n" + "英雄五霸鬧春秋,\n" + "頃刻興亡過手.\n"
+ "青史幾行名姓,\n" + "北邙無數荒丘.\n" + "前人田地後人收,\n" + "說甚龍爭虎斗." + "道德三皇五帝,\n" + "功名夏後商周.\n" + "英雄五霸鬧春秋,\n" + "頃刻興亡過手.\n"
+ "青史幾行名姓,\n" + "北邙無數荒丘.\n" + "前人田地後人收,\n" + "說甚龍爭虎斗." + "道德三皇五帝,\n" + "功名夏後商周.\n" + "英雄五霸鬧春秋,\n" + "頃刻興亡過手.\n"
+ "青史幾行名姓,\n" + "北邙無數荒丘.\n" + "前人田地後人收,\n" + "說甚龍爭虎斗.");
textView.getParent().requestDisallowInterceptTouchEvent(true);
textView.setOnTouchListener(new ZoomListenter());
3. ZoomListenter.java
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.TextView;
public class ZoomListenter implements OnTouchListener {
private int mode = 0;
float oldDist;
float textSize = 0;
TextView textView;
final static float defaultTextSize = 11.0f;
public boolean onTouch(View v, MotionEvent event) {
textView = (TextView) v;
if (textSize == 0) {
textSize = textView.getTextSize();
}
switch (event.getAction() & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_DOWN:
mode = 1;
break;
case MotionEvent.ACTION_UP:
mode = 0;
break;
case MotionEvent.ACTION_POINTER_UP:
mode -= 1;
break;
case MotionEvent.ACTION_POINTER_DOWN:
oldDist = spacing(event);
mode += 1;
break;
case MotionEvent.ACTION_MOVE:
if (mode >= 2) {
float newDist = spacing(event);
if (newDist > oldDist + 1) {
if (textSize < defaultTextSize*3){
zoom(newDist / oldDist);
oldDist = newDist;
}
}
if (newDist < oldDist - 1) {
if (textSize > defaultTextSize){
zoom(newDist / oldDist);
oldDist = newDist;
}
}
}
break;
}
return true;
}
private void zoom(float f) {
textView.setTextSize(textSize *= f);
}
private float spacing(MotionEvent event) {
float x = event.getX(0) - event.getX(1);
float y = event.getY(0) - event.getY(1);
//平方根
return (float) Math.sqrt(x * x + y * y);
}
}
Android中Fragment的兩種創建方式,androidfragmentfragment是Activity中用戶界面的一個行為或者是一部分。你可以在一個單獨的Act
Android用戶界面的組成除了View外,還包括菜單和對話框,本節我們先來學
[android] 手機衛士設置向導頁面,android向導設置向導頁面,通過SharedPreferences來判斷是否已經設置過了,跳轉到不同的頁面 自
總結一下Android中主題(Theme)的正確玩法,androidtheme在AndroidManifest.xml文件中有<application androi