左右TextView旋转门问题
最近由于旋轉門問題的一個客戶找我,當在字符25更多的時候是不是走了,后來,我在重現的問題,發現問題如下面:
?
問題1.人物25幾個月之內可以去。
問題2.在人物25個月,雖然比屏幕寬度,不去
問題3.屏幕寬度能夠走的。
?
查看各種資料。發現例如以下原因導致。但無法解釋問題1.
?
顯示跑馬燈效果的前提條件就是你的文本內容要比顯示文本的外部組件長,即外部組件無法完整的顯示內部的文本內容。
因此要實現跑馬燈效果有兩種設置方式:
1、layout_width=”"設置為成比文本內容短的固定值。最好不要寫成wrap_content或者fill_parent。
2、假設layout_width=”"設置wrap_content或者fill_parent,那么能夠添加上 android:paddingLeft="15dip",android:paddingRight="15dip"使兩端的距離加大而無法所有顯示文本內容。可是這有一個缺陷就是在手機的屏幕變大時。距離沒有變大,外部組件又能夠正常顯示內部文本。于是又無法顯示跑馬燈效果,因此建議第一種設置為佳。
?
修正代碼例如以下:
?
if(wm !=null && mMainPanel != null){
?????try {
??????wm.removeView(mMainPanel);
??????wm = null;
??????mMainPanel = null;
?????} catch (Exception e) {
??????e.printStackTrace();
?????}
????}
????wm = (WindowManager)context.getApplicationContext().getSystemService(Context.WINDOW_SERVICE);
????WindowManager.LayoutParams params = new WindowManager.LayoutParams();
????//設置窗體布局居于全部之上
??????????????? params.type = WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY;
??????????????? //使窗體失去焦點
??????????????? params.flags = WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
??????????????? //背景透明
??????????????? params.format = PixelFormat.RGBA_8888;
??????????????? params.alpha =? 0.7f;//透明度
??????????????
??????????????? params.width = WindowManager.LayoutParams.WRAP_CONTENT;
??????????????? params.height = WindowManager.LayoutParams.WRAP_CONTENT;
???????????????
??????????????? params.x = 0;
??????????????? params.gravity = Gravity.TOP | Gravity.FILL_HORIZONTAL;
???????????????
????isNeedShow = true;
????mMainPanel = (LinearLayout) inflater.inflate(R.layout.notify_message_bottom, null);
????mLinearLayout = (LinearLayout)mMainPanel.findViewById(R.id.no_button_layout);
????mLinearLayout.setOnClickListener(new OnClickListener() {
?????@Override
?????public void onClick(View v) {
??????cancelDialog();
?????}
????});
????titleText = (TextView) mMainPanel.findViewById(R.id.bottem_text);
????DisplayMetrics dm = new DisplayMetrics();
????dm = context.getResources().getDisplayMetrics();
//????titleText.setWidth(dm.widthPixels);
????titleText.setMarqueeRepeatLimit(-1);
????//次數減一才是真正的次數
????Log.d(TAG, "scrollCount: "+(scrollCount-1));
//????titleText.setMarqueeRepeatLimit(scrollCount-1);
????
????String content = mArgs.getTitle()+":"+mArgs.getContent();
????TextPaint paint = titleText.getPaint();
????float len = paint.measureText(content);
????//1280
????Log.d(TAG, "len: "+len+" ,dm.widthPixels: "+dm.widthPixels);
????for (int i = 0; (len < dm.widthPixels); i++) {
?????len = paint.measureText(content);
?????content = content + " ";
????}
????//tcl對接加入了這個。設置長度必須短于文本,否則不滾動。
1288
????Log.d(TAG, "content: "+content);
????Log.d(TAG, "new content: "+paint.measureText(content));
????titleText.setWidth((int)paint.measureText(content)-50);
????titleText.setText(content);
//????titleText.setMovementMethod(ScrollingMovementMethod.getInstance());
????wm.addView(mMainPanel, params);//加入到系統窗體中
?
?
?
版權聲明:本文博主原創文章。博客,未經同意不得轉載。
與50位技術專家面對面20年技術見證,附贈技術全景圖總結
以上是生活随笔為你收集整理的左右TextView旋转门问题的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 如何创建圆角 UITextField 与
- 下一篇: 关于json_decode乱码及NULL