Decode Your Destiny
Find out what your name and birth date say about you and GET YOUR FREE REPORT

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

Add a Comment

Your email address will not be published. Required fields are marked *