How can I implement a collapsible view similar to that of Google Play?

I want to realize a folding view, exactly the same as on the Google Play market. It displays several lines of content and an arrow, and clicking on the arrow shows all the content. Is this implemented using ExpandableListView or is there any other solution?

Screen shots come with the highlight of what I'm looking for. Thank. enter image description here

+17
android android-layout
Jul 03 2018-12-12T00:
source share
2 answers

There is an easier way:

final TextView descriptionText = (TextView) view.findViewById(R.id.detail_description_content); final TextView showAll = (TextView) view.findViewById(R.id.detail_read_all); showAll.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { showAll.setVisibility(View.INVISIBLE); descriptionText.setMaxLines(Integer.MAX_VALUE); } }); 

XML:

 <?xml version="1.0" encoding="utf-8"?> <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <LinearLayout android:id="@+id/detail_description_container" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" > <TextView android:id="@+id/detail_description_content" android:maxLines="5" android:layout_width="match_parent" android:layout_height="wrap_content"/> <TextView android:id="@+id/detail_read_all" android:clickable="true" android:layout_width="wrap_content" android:layout_height="wrap_content"/> </LinearLayout> </ScrollView> 

The important part is maxlines and scrollview. This does not give a slow animation (it would be more difficult to bet), but an instant open effect.

+28
Jul 03 2018-12-15T00:
source share

Sorry my terrible english.

Based on Warpzip answer

 res/values/strings.xml ... ... <string name="str_more"><![CDATA[<p><b>This is the header</b><u>( see more ..)</u>]]></string> <string name="str_less"><![CDATA[<p><b>This is the header</b><u>(less ..)</u>]]></string> <string name="str_details"><![CDATA[<p>A long string of text that do not want to show all the time.A long string of text that do not want to show all the time.A long string of text that do not want to show all the time.A long string of text that do not want to show all the time.A long string of text that do not want to show all the time.</p>]]></string> ... ... 

In our layout in our layout, we can enable scrollview with a vertical LinearLayout (or with a little RelativeLayout work). In them:

 <TextView android:id="@+id/txtvw_header" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:text="@string/str_more" android:textAppearance="?android:attr/textAppearanceMedium" /> <TextView android:id="@+id/txtvw_detail" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_below="@+id/txtvw_tituloEntreTodos" android:text="@string/str_details" android:textAppearance="?android:attr/textAppearanceMedium" /> 

Finally, our activities

  view = inflater.inflate(R.layout.f_entretodos, container, false); info = (TextView) view.findViewById(R.id.txtvw_header); fullinfo = (TextView) view.findViewById(R.id.txtvw_detail); info.setText(Html.fromHtml(getString(R.string.str_more))); fullinfo.setText(Html.fromHtml(getString(R.string.str_detail))); fullinfo.setVisibility(View.GONE); info.setOnClickListener(new OnClickListener(){ @Override public void onClick(View v) { // TODO Auto-generated method stub if (fullinfo.isShown()){ fullinfo.setVisibility(View.GONE); info.setText(Html.fromHtml(getString(R.string.str_more))); }else{ fullinfo.setVisibility(View.VISIBLE); info.setText(Html.fromHtml(getString(R.string.str_less))); } } }); 
+1
Oct 24 '14 at 19:29
source share



All Articles