I want to implement a collapsible view, exactly like the one from Google Play market. It displays a number of rows from the content, and an arrow, and tapping on the arrow reveals the whole content. Is this implemented with the ExpandableListView or is there any other solution?
我想实现一个可折叠的视图,就像Google Play市场一样。它显示内容中的多个行和一个箭头,并点击箭头显示整个内容。这是用ExpandableListView实现的还是有其他解决方案吗?
Screen shots attached with highlighting what I am looking for. Thanks.
屏幕截图附上突出显示我正在寻找的内容。谢谢。
2 个解决方案
#1
30
There is a simpler 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:
<?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 doesn't give a slow animation (that would be a bid more complex) but an instant open effect.
最重要的部分是maxlines和scrollview。这不会给出一个慢动画(这将是一个更复杂的出价),而是一个即时开放效果。
#2
1
Excuse my horrible english.
请原谅我可怕的英语。
Based on Warpzip response
基于Warpzip的回应
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 layoutIn our layout, we can include a scrollview with a vertical LinearLayout (or with a little work a RelativeLayout). In these:
在我们的布局中,在我们的布局中,我们可以包含一个带有垂直LinearLayout的滚动视图(或者稍微使用一个RelativeLayout)。在这些:
<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 Activity
最后我们的活动
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
30
There is a simpler 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:
<?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 doesn't give a slow animation (that would be a bid more complex) but an instant open effect.
最重要的部分是maxlines和scrollview。这不会给出一个慢动画(这将是一个更复杂的出价),而是一个即时开放效果。
#2
1
Excuse my horrible english.
请原谅我可怕的英语。
Based on Warpzip response
基于Warpzip的回应
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 layoutIn our layout, we can include a scrollview with a vertical LinearLayout (or with a little work a RelativeLayout). In these:
在我们的布局中,在我们的布局中,我们可以包含一个带有垂直LinearLayout的滚动视图(或者稍微使用一个RelativeLayout)。在这些:
<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 Activity
最后我们的活动
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)));
}
}
});