Custom android widget.
By default it contains only 3 lines of text and is collapsed. If text is much more, than it will be ellipsized at the end.
By tapping on it, text will expand to it`s full size with alpha animation.
Using:
via xml
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final ExpandableTextView tv = new ExpandableTextView(getApplicationContext());
tv.setText("aadfdsfasasdfadsfdfsfdsfadsfdasfadsfdsafasdfdsfasdfdsafasdfdsafasdfsadfsdfsadfsafasdfsdfafsadfsadfsadfdsafadfsadfsdafdafasdfsdafsdafsdfafsadfafsadfaafs");
tv.setTextColor(Color.BLUE);
tv.setTextSize(20);
tv.setMinLinesCount(2);
this.addContentView(tv, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
}
Sources can be downloaded here
By default it contains only 3 lines of text and is collapsed. If text is much more, than it will be ellipsized at the end.
By tapping on it, text will expand to it`s full size with alpha animation.
Using:
via 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"
tools:context=".MainActivity" xmlns:expandable="http://schemas.android.com/apk/res/com.example.expandable_text">
<ru.gang018.expandabletextview.ui.ExpandableTextView
android:id="@+id/expand"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
expandable:textToExpand="@string/app_name"
expandable:textSize="14sp"
expandable:textColor="@android:color/darker_gray"
expandable:linesCountWhenExpand="4"/>
</RelativeLayout>
via code
@Overridexmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" xmlns:expandable="http://schemas.android.com/apk/res/com.example.expandable_text">
<ru.gang018.expandabletextview.ui.ExpandableTextView
android:id="@+id/expand"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
expandable:textToExpand="@string/app_name"
expandable:textSize="14sp"
expandable:textColor="@android:color/darker_gray"
expandable:linesCountWhenExpand="4"/>
</RelativeLayout>
via code
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final ExpandableTextView tv = new ExpandableTextView(getApplicationContext());
tv.setText("aadfdsfasasdfadsfdfsfdsfadsfdasfadsfdsafasdfdsfasdfdsafasdfdsafasdfsadfsdfsadfsafasdfsdfafsadfsadfsadfdsafadfsadfsdafdafasdfsdafsdafsdfafsadfafsadfaafs");
tv.setTextColor(Color.BLUE);
tv.setTextSize(20);
tv.setMinLinesCount(2);
this.addContentView(tv, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
}
Sources can be downloaded here
Комментариев нет:
Отправить комментарий