Hi guys , today we will be going over a very short tutorial over a simple TextView property of Android.
I am going to be teaching you the Ellipsize property of a TextView in Android.
This property is useful if you have a long text and have a single line to display it.
Ex:
My actual long text :
So, this is just a simple plain old Activity nothing at all in the activity. The real magic begins in the XML Layout file
================================================================
activity_main.xml
================================================================
================================================================
In the above XML all, we did was :
1) Typed some long text , made all the TextViews to show the text in a single Line using
"android:singleLine=true"
2) We then set android:ellipsize property of each textView.
3) We set the Ellipsize property to start,end,middle & marquee which behave as their names suggest.
Thats all for this tutorial , feel free to drop me any comments !
Thanks,
Lets see a screenshot :
I am going to be teaching you the Ellipsize property of a TextView in Android.
This property is useful if you have a long text and have a single line to display it.
Ex:
My actual long text :
This is some real large text so that we can see the ellipsize effect visible and make a demo out of the same for other users
After applying Ellipsize property :
This is some real large text so that we can see the ellipsize effect visible and make a demo out of ...
Usage :
In list Views if the text is too long then the text gets cut off in middle but this is a graceful way of making it look nice. It enhances the User Experience.
So lets get started :
We will just use a single Activity & a simple layout file for demonstrating this.
================================================================
MainActivity.java
MainActivity.java
================================================================
package com.example.testellipsize; import android.os.Bundle; import android.app.Activity; import android.view.Menu; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } }
So, this is just a simple plain old Activity nothing at all in the activity. The real magic begins in the XML Layout file
================================================================
activity_main.xml
================================================================
================================================================
In the above XML all, we did was :
1) Typed some long text , made all the TextViews to show the text in a single Line using
"android:singleLine=true"
2) We then set android:ellipsize property of each textView.
3) We set the Ellipsize property to start,end,middle & marquee which behave as their names suggest.
Thats all for this tutorial , feel free to drop me any comments !
Thanks,
Lets see a screenshot :
As we see the difference is clearly visible, the first TextView shows ... at the start , the second shows at the end similarly 3rd shows in the middle & finally marquee makes the text scroll.
No comments:
Post a Comment