How to Set the Android TextView Width Property?

 

Android TextView Width property makes the TextView be exactly the parametric pixels wide. It should be done the same thing by mention this size  in the LayoutParams. We can set Android TextView Width property in the following two ways mentioned bellow:

 

Set Android TextView Width in XML Editor:

<TextView
android:id="@+id/exampleTextView"
android:layout_width="fill_parent"


android:layout_height="wrap_content"
android:text="@string/hello"
android:width="100dp" />

 

Set Android TextView Width in Java Code:

super.onCreate(savedInstanceState);
setContentView(R.layout.main);


TextView exampleTextView = (TextView)findViewById(R.id.exampleTextView);
exampleTextView.setWidth(100);


exampleTextView.setText("Hello Android - from Rahinur.com");

 

Android TextView Width XML Attribute:
android:width

 

Android TextView Width method:
setWidth(int width)

 

Please Note:

I have test this attribute(Android TextView Width) on Android SDK Version 15

Share This Post

Recent Articles

Leave a Reply

© 2013 Rahinur Rahaman. All rights reserved. Site Admin · Entries RSS · Comments RSS
Powered by WordPress · Designed by Theme Junkie