pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

<small id='sZhCk'></small><noframes id='sZhCk'>

        <legend id='sZhCk'><style id='sZhCk'><dir id='sZhCk'><q id='sZhCk'></q></dir></style></legend>
      1. <tfoot id='sZhCk'></tfoot>

        <i id='sZhCk'><tr id='sZhCk'><dt id='sZhCk'><q id='sZhCk'><span id='sZhCk'><b id='sZhCk'><form id='sZhCk'><ins id='sZhCk'></ins><ul id='sZhCk'></ul><sub id='sZhCk'></sub></form><legend id='sZhCk'></legend><bdo id='sZhCk'><pre id='sZhCk'><center id='sZhCk'></center></pre></bdo></b><th id='sZhCk'></th></span></q></dt></tr></i><div class="bx7ntph" id='sZhCk'><tfoot id='sZhCk'></tfoot><dl id='sZhCk'><fieldset id='sZhCk'></fieldset></dl></div>
        • <bdo id='sZhCk'></bdo><ul id='sZhCk'></ul>

        在代碼和資源中設(shè)置 TextView 字體大小時不一致

        Inconsistency when setting TextView font size in code and in resources(在代碼和資源中設(shè)置 TextView 字體大小時不一致)

          <tfoot id='Qg3Bh'></tfoot>
          • <bdo id='Qg3Bh'></bdo><ul id='Qg3Bh'></ul>
            <i id='Qg3Bh'><tr id='Qg3Bh'><dt id='Qg3Bh'><q id='Qg3Bh'><span id='Qg3Bh'><b id='Qg3Bh'><form id='Qg3Bh'><ins id='Qg3Bh'></ins><ul id='Qg3Bh'></ul><sub id='Qg3Bh'></sub></form><legend id='Qg3Bh'></legend><bdo id='Qg3Bh'><pre id='Qg3Bh'><center id='Qg3Bh'></center></pre></bdo></b><th id='Qg3Bh'></th></span></q></dt></tr></i><div class="5njz5td" id='Qg3Bh'><tfoot id='Qg3Bh'></tfoot><dl id='Qg3Bh'><fieldset id='Qg3Bh'></fieldset></dl></div>

            1. <legend id='Qg3Bh'><style id='Qg3Bh'><dir id='Qg3Bh'><q id='Qg3Bh'></q></dir></style></legend>
                    <tbody id='Qg3Bh'></tbody>

                  <small id='Qg3Bh'></small><noframes id='Qg3Bh'>

                  本文介紹了在代碼和資源中設(shè)置 TextView 字體大小時不一致的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                  問題描述

                  官方文檔似乎沒有回答這個問題,或者我可以想不通.

                  The official documentation does not seem to answer this, or I can't figure it out.

                  元素(別管 AlertDialog,它也發(fā)生在任何 TextView 上):

                  Element (nevermind the AlertDialog, it happens on any TextView as well):

                  TextView tv = (TextView) dialog.findViewById(android.R.id.message);
                  

                  不一致.案例A:

                  tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14);
                  // or tv.setTextSize(14); does the same
                  

                  案例 B:

                  tv.setTextSize(getResources().getDimension(R.dimen.text_size_small));
                  // TypedValue makes no difference either.
                  

                  values/dimens.xml 在哪里:

                  <dimen name="text_size_small">14sp</dimen>
                  

                  結(jié)果:字體大小不一樣,從資源中檢索時顯得更大.我可能遺漏了一些東西,所以我的錯誤是什么,最重要的是:為什么?

                  Result: font size is not the same, and appears much bigger when retrieving from resource. I'm probably missing something, so what's my mistake, and the most important: why?

                  -- 更新到第一個答案--

                  固定數(shù)字只是一個例子,因為沒有人會在代碼中硬編碼固定字體大小.所以讓我重新表述這個問題:

                  The fixed number was just an example, as nobody would hard code fixed font sizes in code. So let me rephrase the question:

                  為什么如果我從代碼中獲取資源,文本大小比我從 XML 布局中獲取資源時大? 此外,問題仍然相同:如何檢索 14sp代碼中的單元并使其與布局 XML 中設(shè)置的 14sp 單元保持一致?我沒有接受答案,因為它沒有告訴我如何在代碼中使用資源中的 sp 單位來獲取文本大小.

                  Why if I get the resource from code, the text size is bigger than when I get the resource from a XML layout? Besides, the question is still the same: how do I retrieve a 14sp unit in code and keep it consistent with the 14sp unit that is set in the layout XML? I did not accept the answer because it does not tell me how to use sp units from resource in code for text size.

                  在這種布局上,字體大小不同,即使尺寸相同:

                  On this layout, the font size is different, even if the dimension is the same:

                  <TextView
                              android:id="@+id/my_text"
                              android:layout_width="wrap_content"
                              android:layout_height="wrap_content"
                              style="@style/TextBody" />
                  

                  styles.xml:

                  styles.xml:

                  <style name="TextBody">
                      <item name="android:textSize">@dimen/text_size_small</item>
                      <item name="android:lineSpacingMultiplier">1.1</item>
                      <item name="android:textColor">@color/body_text_1</item>
                      <item name="android:textIsSelectable">true</item>
                      <item name="android:linksClickable">true</item>
                  </style>
                  

                  看到 text_size_small 了嗎?為什么在這種情況下字體大小比代碼中的小,使用相同的 dimen 資源?

                  See text_size_small there? Why in this case the font size is smaller than in the code, using the same dimen resource?

                  推薦答案

                  你應(yīng)該使用 setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize); 因為 getDimension 方法的文檔聲明它返回一個 Resource 維度值乘以適當(dāng)?shù)闹笜?biāo). 我理解為預(yù)先計算的絕對 px 值.

                  You should use setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize); because the documentation of the getDimension method states that it returns a Resource dimension value multiplied by the appropriate metric. which I understand to be the precalculated absolute px value.

                  即使用:

                  tv.setTextSize(TypedValue.COMPLEX_UNIT_PX, getResources().getDimension(R.dimen.text_size_small));
                  

                  這篇關(guān)于在代碼和資源中設(shè)置 TextView 字體大小時不一致的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                  【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

                  相關(guān)文檔推薦

                  Get user#39;s current location using GPS(使用 GPS 獲取用戶的當(dāng)前位置)
                  IllegalArgumentException thrown by requestLocationUpdate()(requestLocationUpdate() 拋出的 IllegalArgumentException)
                  How reliable is LocationManager#39;s getLastKnownLocation and how often is it updated?(LocationManager 的 getLastKnownLocation 有多可靠,多久更新一次?)
                  How to detect Location Provider ? GPS or Network Provider(如何檢測位置提供者?GPS 或網(wǎng)絡(luò)提供商)
                  Get current location during app launch(在應(yīng)用啟動期間獲取當(dāng)前位置)
                  locationManager.getLastKnownLocation() return null(locationManager.getLastKnownLocation() 返回 null)

                      <bdo id='5NVSR'></bdo><ul id='5NVSR'></ul>
                      <i id='5NVSR'><tr id='5NVSR'><dt id='5NVSR'><q id='5NVSR'><span id='5NVSR'><b id='5NVSR'><form id='5NVSR'><ins id='5NVSR'></ins><ul id='5NVSR'></ul><sub id='5NVSR'></sub></form><legend id='5NVSR'></legend><bdo id='5NVSR'><pre id='5NVSR'><center id='5NVSR'></center></pre></bdo></b><th id='5NVSR'></th></span></q></dt></tr></i><div class="5dhh5dn" id='5NVSR'><tfoot id='5NVSR'></tfoot><dl id='5NVSR'><fieldset id='5NVSR'></fieldset></dl></div>
                        <tbody id='5NVSR'></tbody>

                      <small id='5NVSR'></small><noframes id='5NVSR'>

                    • <tfoot id='5NVSR'></tfoot>
                          <legend id='5NVSR'><style id='5NVSR'><dir id='5NVSR'><q id='5NVSR'></q></dir></style></legend>

                          • 主站蜘蛛池模板: 环保袋,无纺布袋,无纺布打孔袋,保温袋,环保袋定制,环保袋厂家,环雅包装-十七年环保袋定制厂家 | 实验室pH计|电导率仪|溶解氧测定仪|离子浓度计|多参数水质分析仪|pH电极-上海般特仪器有限公司 | 宝宝药浴-产后药浴-药浴加盟-艾裕-专注母婴调养泡浴 | 电采暖锅炉_超低温空气源热泵_空气源热水器-鑫鲁禹电锅炉空气能热泵厂家 | 生态板-实木生态板-生态板厂家-源木原作生态板品牌-深圳市方舟木业有限公司 | 颚式破碎机,圆锥破碎机,制砂机-新乡市德诚机电制造有限公司 | 哈尔滨治「失眠/抑郁/焦虑症/精神心理」专科医院排行榜-京科脑康免费咨询 一对一诊疗 | 金属抛光机-磁悬浮抛光机-磁力研磨机-磁力清洗机 - 苏州冠古科技 | 精准猎取科技资讯,高效阅读科技新闻_科技猎| 烟台螺纹,烟台H型钢,烟台钢材,烟台角钢-烟台市正丰金属材料有限公司 | 高博医疗集团上海阿特蒙医院 | 百方网-百方电气网,电工电气行业专业的B2B电子商务平台 | 上海璟文空运首页_一级航空货运代理公司_机场快递当日达 | 温州中研白癜风专科_温州治疗白癜风_温州治疗白癜风医院哪家好_温州哪里治疗白癜风 | TPM咨询,精益生产管理,5S,6S现场管理培训_华谋咨询公司 | 三效蒸发器_多效蒸发器价格_四效三效蒸发器厂家-青岛康景辉 | 塑料托盘厂家直销-吹塑托盘生产厂家-力库塑业【官网】 | 金联宇电缆总代理-金联宇集团-广东金联宇电缆实业有限公司 | 掺铥光纤放大器-C/L波段光纤放大器-小信号光纤放大器-合肥脉锐光电技术有限公司 | 广州网站建设_小程序开发_番禺网站建设_佛山网站建设_粤联网络 | 东莞市海宝机械有限公司-不锈钢分选机-硅胶橡胶-生活垃圾-涡电流-静电-金属-矿石分选机 | BOE画框屏-触摸一体机-触控查询一体机-触摸屏一体机价格-厂家直销-触发电子 | 压力喷雾干燥机,喷雾干燥设备,柱塞隔膜泵-无锡市闻华干燥设备有限公司 | 创绿家招商加盟网-除甲醛加盟-甲醛治理加盟-室内除甲醛加盟-创绿家招商官网 | 闪蒸干燥机-喷雾干燥机-带式干燥机-桨叶干燥机-[常州佳一干燥设备] | 合肥白癜风医院_合肥治疗白癜风医院_合肥看白癜风医院哪家好_合肥华研白癜风医院 | ptc_浴霸_大巴_干衣机_呼吸机_毛巾架_电动车加热器-上海帕克 | 机器视觉检测系统-视觉检测系统-机器视觉系统-ccd检测系统-视觉控制器-视控一体机 -海克易邦 | SMC-ASCO-CKD气缸-FESTO-MAC电磁阀-上海天筹自动化设备官网 | 仓储笼_仓储货架_南京货架_仓储货架厂家_南京货架价格低-南京一品仓储设备制造公司 | 北京康百特科技有限公司-分子蒸馏-短程分子蒸馏设备-实验室分子蒸馏设备 | 档案密集架_电动密集架_移动密集架_辽宁档案密集架-盛隆柜业厂家现货批发销售价格公道 | 铸铝门厂家,别墅大门庭院大门,别墅铸铝门铜门[十大品牌厂家]军强门业 | 北京网络营销推广_百度SEO搜索引擎优化公司_网站排名优化_谷歌SEO - 北京卓立海创信息技术有限公司 | 涡轮流量计_LWGY智能气体液体电池供电计量表-金湖凯铭仪表有限公司 | 苏州伊诺尔拆除公司_专业酒店厂房拆除_商场学校拆除_办公楼房屋拆除_家工装拆除拆旧 | 一氧化氮泄露报警器,二甲苯浓度超标报警器-郑州汇瑞埔电子技术有限公司 | 深圳3D打印服务-3D打印加工-手板模型加工厂-悟空打印坊 | 冷库安装厂家_杭州冷库_保鲜库建设-浙江克冷制冷设备有限公司 | 冷藏车-东风吸污车-纯电动环卫车-污水净化车-应急特勤保障车-程力专汽厂家-程力专用汽车股份有限公司销售二十一分公司 | 火锅底料批发-串串香技术培训[川禾川调官网] |