Friday, 4 October 2013

Developed using Eclipse 4.3.0, Android API Level 18 

This tutorial will show you the use of "Ellipsize Property in Android"

File: activity_main.xml


<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

    xmlns:tools="http://schemas.android.com/tools"

    android:layout_width="match_parent"

    android:layout_height="match_parent"

    android:paddingBottom="@dimen/activity_vertical_margin"

    android:paddingLeft="@dimen/activity_horizontal_margin"

    android:paddingRight="@dimen/activity_horizontal_margin"

    android:paddingTop="@dimen/activity_vertical_margin"

    tools:context=".MainActivity" >



    <TextView

        android:id="@+id/textView1"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:layout_alignParentLeft="true"

        android:layout_alignParentTop="true"

        android:ellipsize="none"

        android:text="@string/longText1"

        android:textSize="15sp"

        android:typeface="sans"

        android:singleLine="true"/>



    <TextView

        android:id="@+id/textView2"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:layout_alignLeft="@+id/textView1"

        android:layout_alignRight="@+id/textView1"

        android:layout_below="@+id/textView1"

        android:layout_marginTop="30dp"

        android:ellipsize="start"

        android:text="@string/longText1"

        android:textSize="15sp"

        android:typeface="sans" 

        android:singleLine="true" />



    <TextView

        android:id="@+id/textView3"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:layout_alignLeft="@+id/textView2"

        android:layout_alignRight="@+id/textView2"

        android:layout_below="@+id/textView2"

        android:layout_marginTop="30dp"

        android:ellipsize="middle"

        android:text="@string/longText1"

        android:textSize="15sp"

        android:typeface="sans" 

        android:singleLine="true" />



    <TextView

        android:id="@+id/textView5"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:layout_alignLeft="@+id/textView4"

        android:layout_alignRight="@+id/textView4"

        android:layout_below="@+id/textView4"

        android:layout_marginTop="30dp"

        android:ellipsize="marquee"

        android:text="@string/longText1"

        android:textSize="15sp"

        android:typeface="sans"

        android:singleLine="true" />



    <TextView

        android:id="@+id/textView4"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:layout_alignLeft="@+id/textView3"

        android:layout_below="@+id/textView3"

        android:layout_marginTop="30dp"

        android:ellipsize="end"

        android:text="@string/longText1"

        android:textSize="15sp"

        android:typeface="sans" 

        android:singleLine="true" />



</RelativeLayout>


Ellipsize Property of TextView in Android
Ellipsize Property of TextView in Android


File: MainActivity.java


package com.mavenscientists.ellipsizeproperty;

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;
 }

}
File: res/values/strings.xml


<?xml version="1.0" encoding="utf-8"?>
<resources>

    <string name="app_name">Ellipsize Property</string>
    <string name="action_settings">Settings</string>
    <string name="hello_world">Hello world!</string>
    <string name="longText1">I am learning the Ellipsize Property in android at mavenscientists.com</string>

</resources>

Get Ebooks delivered to your email id

Comments

Subscribe to our channel

Facebook

Powered by Blogger.

Home | Contact Us | DMCA | Terms of Service | Privacy | Advertise

Maven Scientists