Buggy code:
public class TestFragment7 extends Fragment { private static final String ARG_PARAM1 = "param1" ; private static final String ARG_PARAM2 = "param2" ; private String mParam1 ; private String mParam2 ; String [ ] headlines ; String [ ] publications ; Fragment mFragment ; FragmentManager manager ; Bundle args ; private TestFragment7 . OnFragmentInteractionListener mListener ; public static TestFragment7 newInstance ( String param1 , String param2 ) { } public TestFragment7 ( ) { } @ Override public void onCreate ( Bundle savedInstanceState ) { } @ Override public View onCreateView ( LayoutInflater inflater , ViewGroup container , Bundle savedInstanceState ) { View view = inflater . inflate ( fragment_test_fragment7 , container , false ) ; int dpValue = 20 ; float d = getResources ( ) . getDisplayMetrics ( ) . density ; int margin = ( ( int ) ( dpValue * d ) ) ; manager = getFragmentManager ( ) ; mFragment = new PDFFragment ( ) ; args = new Bundle ( ) ; headlines = getResources ( ) . getStringArray ( R . array . publications ) ; publications = getResources ( ) . getStringArray ( publication_urls ) ; LinearLayout ll = ( ( LinearLayout ) ( view . findViewById ( publications_layout ) ) ) ; ll . setPadding ( margin , margin , margin , margin ) ; for ( int i = 0 ; i < ( headlines . length ) ; i ++ ) { final int j = i ; LinearLayout innerLayout = new LinearLayout ( container . getContext ( ) ) ; LinearLayout . LayoutParams params = new LinearLayout . LayoutParams ( LayoutParams . MATCH_PARENT , LayoutParams . WRAP_CONTENT ) ; params . setMargins ( 0 , 0 , 0 , margin ) ; innerLayout . setLayoutParams ( params ) ; innerLayout . setGravity ( CENTER_VERTICAL ) ; innerLayout . setOrientation ( HORIZONTAL ) ; innerLayout . setBackgroundDrawable ( getResources ( ) . getDrawable ( layout_bg ) ) ; innerLayout . setPadding ( margin , margin , margin , margin ) ; TextView tv1 = new TextView ( container . getContext ( ) ) ; tv1 . setText ( Html . fromHtml ( headlines [ i ] ) ) ; tv1 . setTextColor ( getResources ( ) . getColor ( text_color ) ) ; <START_BUG> tv1 . setTextSize ( COMPLEX_UNIT_SP , 18 ) ; <END_BUG> LinearLayout . LayoutParams params1 = new LinearLayout . LayoutParams ( LayoutParams . WRAP_CONTENT , LayoutParams . WRAP_CONTENT ) ; params1 . setMargins ( 0 , 0 , margin , 0 ) ; ImageButton btn = new ImageButton ( getActivity ( ) ) ; btn . setImageResource ( pdf_icon ) ; btn . setBackgroundDrawable ( getResources ( ) . getDrawable ( textview_bg ) ) ; btn . setOnClickListener ( new View . OnClickListener ( ) { @ Override public void onClick ( View v ) { args . putString ( "URL" , ( "https:////docs.google.com//gview?embedded=true&url=" + ( publications [ j ] . toString ( ) ) ) ) ; mFragment . setArguments ( args ) ; manager . beginTransaction ( ) . replace ( content_frame , mFragment ) . addToBackStack ( mFragment . toString ( ) ) . commit ( ) ; } } ) ; if ( ! ( publications [ j ] . toString ( ) . isEmpty ( ) ) ) { innerLayout . addView ( btn , params1 ) ; } innerLayout . addView ( tv1 ) ; ll . addView ( innerLayout ) ; } return view ; } public void onButtonPressed ( Uri uri ) { } @ Override public void onAttach ( Activity activity ) { } @ Override public void onDetach ( ) { } public interface OnFragmentInteractionListener { public void onFragmentInteraction ( Uri uri ) { } } }

Fix:
tv1 . setTextSize ( COMPLEX_UNIT_SP , 22 ) ;