久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

<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="qwawimqqmiuu" id='sZhCk'><tfoot id='sZhCk'></tfoot><dl id='sZhCk'><fieldset id='sZhCk'></fieldset></dl></div>
        • <bdo id='sZhCk'></bdo><ul id='sZhCk'></ul>

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

        Inconsistency when setting TextView font size in code and in resources(在代碼和資源中設置 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="qwawimqqmiuu" 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'>

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

                  問題描述

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

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

                  元素(別管 AlertDialog,它也發生在任何 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>
                  

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

                  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?

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

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

                  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 中設置的 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?

                  推薦答案

                  你應該使用 setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize); 因為 getDimension 方法的文檔聲明它返回一個 Resource 維度值乘以適當的指標. 我理解為預先計算的絕對 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));
                  

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

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

                  相關文檔推薦

                  Get user#39;s current location using GPS(使用 GPS 獲取用戶的當前位置)
                  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 或網絡提供商)
                  Get current location during app launch(在應用啟動期間獲取當前位置)
                  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="qwawimqqmiuu" 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>

                          • 主站蜘蛛池模板: 欧美日韩一区二区在线 | 国产一区二区三区免费观看在线 | 亚洲一区二区三区四区五区午夜 | 亚洲成人自拍网 | 欧美综合在线观看 | 日本色综合| 欧美乱做爰xxxⅹ久久久 | 久久国产精品无码网站 | 亚洲福利视频网 | 在线资源视频 | 亚洲有码转帖 | 国产精品二区三区 | 中文字幕一区二区三区乱码图片 | 国产高清在线观看 | 成人在线视频免费观看 | 国产精品久久久久久久久图文区 | 久草福利 | 欧美激情第一区 | 亚洲成人观看 | 久久精品国产一区二区三区不卡 | 亚洲精品乱码久久久久久按摩 | 欧洲精品视频一区 | 日日日干干干 | 7777在线 | 草草视频在线观看 | 国产人成在线观看 | 91超碰在线| 中文字幕国产一区 | 国产一区二区精品在线 | 欧产日产国产精品99 | 亚洲国产一区二区三区在线观看 | 欧美片网站免费 | 国产免费自拍 | 亚洲精品久久久久久一区二区 | 色性av| 日韩久久综合 | 鸳鸯谱在线观看高清 | 精品国产乱码久久久久久老虎 | 日韩av免费在线观看 | 久久久久久久久国产 | 久久精品欧美视频 |