Font size of text

后端 未结 8 1977
伪装坚强ぢ
伪装坚强ぢ 2021-01-29 04:29

I have created different layouts (layout, layout-small, layout-normal, layout-large, layout-xlarge) and for values (values, values-ldpi, values-mdpi, values-n

相关标签:
8条回答
  • 2021-01-29 04:59

    Just instead yourvalues (values, values-ldpi, values-mdpi, values-nodpi, values-hdpi, values-xhdpi), which are specifying the text font sizes for each density.

    Use text size specification based on screen size, like this:values (values, values-small, values-normal, values-large, values-xlarge)

    Alternatively to obtain better results for various devices you can combine density with screen size, like this:values-normal-mdpi

    That's all

    0 讨论(0)
  • 2021-01-29 05:03

    Actually you don't need to create all these layout directories to handle text size. Just stick with the normal one (layout) and create different values directories with different text size for each resolution you want to support. so you have to add text size in other values directories.

    At run-time Android will pick the correct text size.

    0 讨论(0)
  • 2021-01-29 05:09

    you are using only portrait version, if you are using same structure of design for all devices you don't need to add four different layout for each pixel density.

    create android values folders that supports different screen sizes.

    enter image description here

    Here first folder for 7inch android devices that have ANDROID version 3.1 or less. second one is for 7inch devices that have android version greater than 3.1. naming convention sw600 means smallest width of 600. so this folder works for width size 600 to 720. So create values-sw480dp and values-sw320 add values to dimens.xml file.

    Android runtime automatically picks values from appropriate folder.

    0 讨论(0)
  • 2021-01-29 05:11

    Try like this

    STEP : 1 first in res folder => values => dimensions.xml=> create dimensions.xml file to values folder in that create like below code depending on textsize

         <?xml version="1.0" encoding="utf-8"?>
           <resources>
               <dimen name="textsize">8sp</dimen>
               <dimen name="text">10sp</dimen>
               <dimen name="comments">7sp</dimen>
           </resources>
    

    STEP : 2 in java file write this line

          TextView textviewtwo = (TextView)findViewById(R.id.sponsertwo_txt);
    textviewtwo.setText("brought to you by");    
    textviewtwo.setTextSize(TypedValue.COMPLEX_UNIT_PX,
      getResources().getDimension(R.dimen.textsize));
          // in place of textsize use text and comments what ever we want depending on size. use like text size                  adjust automatically in all devices 
    
    0 讨论(0)
  • 2021-01-29 05:13

    Try to add this in your AndroidManifest.xml

    <supports-screens android:anyDensity="true"
                      android:largeScreens="true"
                      android:normalScreens="true"
                      android:resizeable="true"
                      android:smallScreens="true"/>
    
    0 讨论(0)
  • 2021-01-29 05:17

    Use this code, it works based on screen size:

    Display display = getWindowManager().getDefaultDisplay();
    int displayWidth = display.getWidth();
    
    yourTextView.setTextSize(TypedValue.COMPLEX_UNIT_PX,(float)(displayWidth * 6/100));
    
    0 讨论(0)
提交回复
热议问题