目前分類:畫面 (9)
- Nov 05 Tue 2019 16:47
android recycleView + databinding
- Nov 04 Mon 2019 16:44
android recycleView
- Jul 11 Wed 2018 17:17
android textview 特定區間做特效
Spannable span = new SpannableString(Text); int start = 0; int end = 0; while (start != -1 ) {//title setting textSpan start = content4.getText().toString().indexOf("\n \n", end);//區間開頭 end = content4.getText().toString().indexOf("\n", content4.getText().toString().indexOf("\n \n", end) + 4);//區間結尾 if(end > start && start >= 0)//有取得正確的開頭和結尾索引則新增特效 span.setSpan(new AbsoluteSizeSpan(28), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);//字體放大為28 } textview.setText(span);
- Jul 10 Tue 2018 14:03
android animation動畫
放大動畫
* @param startScaleX x原本比例 * @param startScaleY y原本比例 * @param endScaleX x放大比例 * @param endScaleY y放大比例 * @param positionX 轉的位置 getPivotX()為中心 0為左邊 getX()為右邊 * @param positionY 轉的位置 getPivotY()為中心 0為上面 getY()為下面
Animation animation = new ScaleAnimation(startScaleX, endScaleX,startScaleY,endScaleY,positionX,positionY); 平移動畫
* @param startX 開始的X(以左上角為0) * @param startY 開始的Y(以左上角為0) * @param endX 往右移動多少X * @param endY 往下移動多少Y
Animation animation = new TranslateAnimation(startX, endX,startY,endY);
轉圈動畫
* @param startAngle 開始轉的角度 * @param endAngle 結束停的角度 * @param Xcenter 轉的中心點X * @param Ycenter 轉的中心點Y
Animation animation = new RotateAnimation(startAngle, endAngle, Animation.RELATIVE_TO_SELF, Xcenter, Animation.RELATIVE_TO_SELF, Ycenter);
-------------------------------------------------------------------------------------------------------------------------------------- animation.setInterpolator(new LinearInterpolator());//順順的動 animation.setDuration(cycleTime);//轉動時間ms animation.setRepeatCount(Animation.INFINITE);//設定動畫執行次數(INFINITE為重複)
- May 17 Thu 2018 10:11
動態設定dp.sp
取得dp TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,(float) 長度,getResources().getDisplayMetrics()) 取得sp TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP,(float) 長度,getResources().getDisplayMetrics()) 取得pt TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_PT,(float) 長度,getResources().getDisplayMetrics()) 取得px TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_PX,(float) 長度,getResources().getDisplayMetrics()) 取得mm TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_MM,(float) 長度,getResources().getDisplayMetrics())
- May 11 Fri 2018 14:33
android ui 佈局對齊
layout_gravity 物件相對於父物件的位置
gravity 物件內資料的位置
- Aug 05 Fri 2016 12:07
android系統層介面
WindowManager windowManager = null;//系統層
WindowManager.LayoutParams params = null;//排版 params = new WindowManager.LayoutParams(//排版設定 WindowManager.LayoutParams.FLAG_LAYOUT_IN_OVERSCAN, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, PixelFormat.TRANSLUCENT); windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
params.width = WindowManager.LayoutParams.MATCH_PARENT;//物件layout的寬 params.height = 60; params.gravity = Gravity.TOP;//物件layout的位子 titleBG = new ImageView(this);//物件init titleBG.setBackgroundColor(Color.parseColor("#501f2424"));//物件設定圖片及顏色 windowManager.addView(titleBG, params);//將物件及排版加入windowManager
- Jul 29 Fri 2016 14:38
剛開啟app時會有白黑屏
<application
android:theme="@style/translucent">
</application>
//背景透明
<style name="translucent" parent="@android:style/Theme.Translucent"> <item name="android:windowNoTitle">true</item> </style>
//背景設定一張圖片
- May 26 Thu 2016 18:03
textview scroll
.xml <TextView android:scrollbars = "vertical"/>
程式碼:
private int pageIndex = 0 ;
private TextView text;
text = (TextView) findViewById(R.id.text); text.setMovementMethod(new ScrollingMovementMethod(){ @Override public boolean onKeyDown(TextView widget, Spannable text, int keyCode, KeyEvent event) { if(keyCode == KeyEvent.KEYCODE_DPAD_DOWN){// nextText(); return false; }else if(keyCode == KeyEvent.KEYCODE_DPAD_UP){ preText(); return false; } return super.onKeyDown(widget, text, keyCode, event); } });
private void nextText(){ if(pageIndex == 0){ image.setVisibility(View.GONE); text.scrollTo(0, text.getLayout().getLineTop(行數* (pageIndex+1))); pageIndex++; }else if(text.canScrollVertically(1)){ text.scrollTo(0, text.getLayout().getLineTop(行* (pageIndex+1))); pageIndex++; } }