Headertab

Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

Saturday, 12 March 2016

ExpandableTextView

Hello friends this blog about how to create ExpandableTextView.

activity_main.xml 

<?xml version="1.0" encoding="utf-8"?>
<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"
    xmlns:expandableTextView="http://schemas.android.com/apk/res-auto"
    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="com.samset.expandabletextview.MainActivity">


    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">


            <com.samset.expandabletextview.expandabletextview.ExpandableTextView
                android:id="@+id/expand_text_view"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                expandableTextView:maxCollapsedLines="4">
                <RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content">
                    <TextView
                        android:id="@+id/expandable_text"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:fontFamily="sans-serif-light"
                        android:textSize="16sp"
                        android:textColor="#666666" />
                    <RelativeLayout
                        android:layout_below="@+id/expandable_text"
                        android:id="@+id/layout_rate"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_centerVertical="true"
                        android:background="@color/green_text"
                        android:padding="7dp">


                        <TextView
                            android:id="@+id/help"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_alignParentLeft="true"
                            android:layout_centerVertical="true"
                            android:layout_marginLeft="10dp"
                            android:text="Is it helpful Sample ?"
                            android:layout_gravity="left|bottom"
                            android:textAppearance="?android:textAppearanceMedium"
                            android:textColor="#fff" />
                        <Button
                            android:id="@+id/btn_help"
                            android:layout_width="50dp"
                            android:layout_height="30dp"
                            android:layout_centerVertical="true"
                            android:layout_marginLeft="5dp"
                            android:layout_toRightOf="@+id/help"
                            android:background="@color/darkprimary_color"
                            android:text="Yes"
                            android:textColor="@color/green_text" />
                    </RelativeLayout>


                    <RelativeLayout
                        android:layout_marginRight="10dp"
                        android:layout_below="@+id/expandable_text"
                        android:layout_alignParentRight="true"
                        android:layout_centerVertical="true"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content">
                        <TextView
                            android:id="@+id/txt_collapse"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_centerVertical="true"
                            android:text="Click"
                            android:layout_marginRight="5dp"
                            android:layout_toLeftOf="@+id/expand_collapse"
                            android:textAppearance="?android:textAppearanceMedium"
                            android:textColor="@color/green_text" />
                        <ImageButton
                            android:id="@id/expand_collapse"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_alignParentRight="true"
                            android:layout_centerVertical="true"
                            android:background="@android:color/transparent"/>
                    </RelativeLayout>
                </RelativeLayout>
            </com.samset.expandabletextview.expandabletextview.ExpandableTextView>
        </LinearLayout>

    </ScrollView>
</RelativeLayout>

ActivityMain.java

public class MainActivity extends AppCompatActivity {
private ExpandableTextView expandableTextView;




    String str;
    private final String htmlText = "HTTP is the way modern applications network. It’s how we exchange data & media. Doing HTTP efficiently makes your stuff load faster and saves bandwidth.\n" +
            "\n" +
            "OkHttp is an HTTP client that’s efficient by default:\n" +
            "\n" +
            "HTTP/2 support allows all requests to the same host to share a socket.\n" +
            "Connection pooling reduces request latency (if HTTP/2 isn’t available).\n" +
            "Transparent GZIP shrinks download sizes.\n" +
            "Response caching avoids the network completely for repeat requests.\n" +
            "OkHttp perseveres when the network is troublesome: it will silently recover from common connection problems. If your service has multiple IP addresses OkHttp will attempt alternate addresses if the first connect fails. This is necessary for IPv4+IPv6 and for services hosted in redundant data centers. OkHttp initiates new connections with modern TLS features (SNI, ALPN), and falls back to TLS 1.0 if the handshake fails.\n" +
            "\n" +
            "Using OkHttp is easy. Its request/response API is designed with fluent builders and immutability. It supports both synchronous blocking calls and async calls with callbacks.\n" +
            "\n" +
            "OkHttp supports Android 2.3 and above. For Java, the minimum requirement is 1.7." +
            "If you would like to contribute code you can do so through GitHub by forking the repository and sending a pull request.\n" +
            "\n" +
            "When submitting code, please make every effort to follow existing conventions and style in order to keep the code as readable as possible. Please also make sure your code compiles by running mvn clean verify.\n" +
            "\n" +
            "Before your code can be accepted into the project you must also sign the Individual Contributor License Agreement (CLA)";


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);




        expandableTextView= (ExpandableTextView) findViewById(R.id.expand_text_view);
        expandableTextView.setText(htmlText);
    }

}


Thank you
I hope helps this blog.

Source code 


https://github.com/SamsetDev/ExpandableTextView