manabu-gt / expandabletextview Goto Github PK
View Code? Open in Web Editor NEWAndroid's TextView that can expand/collapse like the Google Play's app description
License: Apache License 2.0
Android's TextView that can expand/collapse like the Google Play's app description
License: Apache License 2.0
when ExpandableTextView parent layout set width 0dp and set weight ,the maxCollapsedLines not work , the text will all show . but when set ExpandableTextView parent layout width "match_parent" and set weight , the maxCollapsedLines work fine .
The problem is mentioned on tilte..
Is it possible to add more views in the list item, such as another textview, or a radio button? where these views will be visible on expand and invisible on collapse.
Thank you,
Hi, I want to remove the image button and add my custom button but it will crash, so I tried to hide the image button but this code is not working android: visibility="gone"
. the image button will display even I added this code. So how to hide it?
My custom button just displays a 'Read More' text and no image.
Or I have to create 'read more' image for it? any other solution?
<com.ms.square.android.expandabletextview.ExpandableTextView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:expandableTextView="http://schemas.android.com/apk/res-auto"
android:id="@+id/expand_text_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
expandableTextView:animDuration="200">
<TextView
android:id="@id/expandable_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#666666"
android:textSize="16sp" />
<ImageButton
android:id="@id/expand_collapse"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left|bottom"
android:background="@android:color/transparent"
android:visibility="gone"
android:padding="16dp"
android:text="Read More"
android:textColor="@color/colorSweat"/>
</com.ms.square.android.expandabletextview.ExpandableTextView>
Setting HTML text as a part of ExpandableTextView using (Html.fromHtml(String, int)) . when there are hyperlinks as a part of HTML content its display as a link. the clicking of that link will collapse the view instead of opening that in browser.
Is the textview which is wrapped in ExpandableTextView (LinearLayout) is
textview.setMovementMethod(LinkMovementMethod.getInstance()); ??
how to know it is expand and collapsed。
how do U setXXXX(), this is Defult Open~~
Can't expand when click the icon ,onMeasure not be called by system
java.lang.NullPointerException
at com.ms.square.android.expandabletextview.ExpandableTextView.findViews(ExpandableTextView.java:226)
at com.ms.square.android.expandabletextview.ExpandableTextView.onFinishInflate(ExpandableTextView.java:151)
at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:814)
at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:64)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:782)
at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:809)
at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:64)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:782)
at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:809)
at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:64)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:782)
at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:809)
at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:64)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:782)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:385)
at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:400)
at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:332)
at com.android.ide.common.rendering.LayoutLibrary.createSession(LayoutLibrary.java:350)
at com.android.tools.idea.rendering.RenderService$5.compute(RenderService.java:688)
at com.android.tools.idea.rendering.RenderService$5.compute(RenderService.java:677)
at com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:932)
at com.android.tools.idea.rendering.RenderService.createRenderSession(RenderService.java:677)
at com.android.tools.idea.rendering.RenderService.render(RenderService.java:815)
at org.jetbrains.android.uipreview.AndroidLayoutPreviewToolWindowManager.doRender(AndroidLayoutPreviewToolWindowManager.java:646)
at org.jetbrains.android.uipreview.AndroidLayoutPreviewToolWindowManager.access$1700(AndroidLayoutPreviewToolWindowManager.java:82)
at org.jetbrains.android.uipreview.AndroidLayoutPreviewToolWindowManager$7$1.run(AndroidLayoutPreviewToolWindowManager.java:589)
at com.intellij.openapi.progress.impl.ProgressManagerImpl$2.run(ProgressManagerImpl.java:178)
at com.intellij.openapi.progress.ProgressManager.executeProcessUnderProgress(ProgressManager.java:209)
at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:212)
at com.intellij.openapi.progress.impl.ProgressManagerImpl.runProcess(ProgressManagerImpl.java:171)
at org.jetbrains.android.uipreview.AndroidLayoutPreviewToolWindowManager$7.run(AndroidLayoutPreviewToolWindowManager.java:584)
at com.intellij.util.ui.update.MergingUpdateQueue.execute(MergingUpdateQueue.java:320)
at com.intellij.util.ui.update.MergingUpdateQueue.execute(MergingUpdateQueue.java:310)
at com.intellij.util.ui.update.MergingUpdateQueue$2.run(MergingUpdateQueue.java:254)
at com.intellij.util.ui.update.MergingUpdateQueue.flush(MergingUpdateQueue.java:269)
at com.intellij.util.ui.update.MergingUpdateQueue.flush(MergingUpdateQueue.java:227)
at com.intellij.util.ui.update.MergingUpdateQueue.run(MergingUpdateQueue.java:217)
at com.intellij.util.concurrency.QueueProcessor.runSafely(QueueProcessor.java:238)
at com.intellij.util.Alarm$Request$1.run(Alarm.java:327)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
This error, im using Android Studio & Gradle.
compile 'com.ms-square:expandableTextView:0.1.3'
hi
i just replaced the TextView in the lib with this HtmlTextView which extends TextView itself. expanding works fine but collapsig wont work.
where is the problem?
thanks in advance
mTv = (TextView) findViewById(R.id.expandable_text);
mButton = (ImageButton) findViewById(R.id.expand_collapse);
These lines in findViews
mean that the id for the children of ExpandableTextView must be expandable_text
and expandand_collapse
for the TextView and ImageButton respectively.
I initially changed the ids in my XML layout and slammed into a null-pointer exception until i dug into the code. It will nice if this "limitation" is made known to users or better still, remove the hard coded ids. I can submit a pull request to remove the hard coded ids.
和recyclerview配合一起使用的时候反复下拉刷新 ExpandableTextView距离下面控件的距离越来越大 是什么问题
Are you still support this library @Manabu-GT ?
Hi, first of all , awesome library because yours probably is the only one that does this. I am using your library with a recyclerview in my code. I set 3 lines to be displayed in my custom_item
As you saw the issue, some items expand once, the collapse incorrectly and never expand again, any ideas ,if you need any more source files , please let me know, thanks in advance for your help
public class AdapterFeed extends UltimateViewAdapter {
private Context mContext;
private ArrayList mListFeed = new ArrayList<>();
private LayoutInflater mLayoutInflater;
private EventListener mEventListener;
private SparseBooleanArray mTogglePositions = new SparseBooleanArray();
public AdapterFeed(Context context) {
this.mContext = context;
mLayoutInflater = LayoutInflater.from(context);
setHasStableIds(true);
}
public void setFeed(ArrayList<Post> listFeed) {
if (listFeed != null && listFeed.size() > 0) {
mListFeed = listFeed;
notifyItemRangeChanged(0, listFeed.size());
}
}
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
if (holder instanceof HolderFeed) {
Post currentPost = mListFeed.get(position);
HolderFeed holderFeed = (HolderFeed) holder;
holderFeed.textPost.setText(Post.isNotEmptyMessage(currentPost) ? currentPost.getMessage() : "No Text", mTogglePositions, position);
}
}
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup viewGroup) {
View layout = mLayoutInflater.inflate(R.layout.item_feed, viewGroup, false);
HolderFeed holderFeed = new HolderFeed(layout);
return holderFeed;
}
@Override
public int getAdapterItemCount() {
return mListFeed.size();
}
static class HolderFeed extends RecyclerView.ViewHolder {
private ExpandableTextView textPost;
public HolderFeed(View itemView) {
super(itemView);
textPost = (ExpandableTextView) itemView.findViewById(R.id.expand_text_view);
}
}
}
Can we change drawable of up and down?
In a RecyclerView i have other view, if the TextView is expanded and you scroll,the other view in some item has gone please give me some suggestion
I use the lib of Ultra-pull-to-refresh to show a list.The expandableTextView is used in the itemview.But they can not work fine.The url is "https://github.com/liaohuqiu/android-Ultra-Pull-To-Refresh".How shuld I to fix it?
when i tried to implement the expandable text-view in a list view The expand and collapse icons are not appearing could you please help me out if i am doing wrong
MyCode: List_rowitem
<!-- ListRow Left sied Thumbnail image -->
<LinearLayout android:id="@+id/thumbnail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="3dip"
android:layout_alignParentLeft="true"
android:background="@android:color/transparent"
android:layout_marginRight="5dp">
<ImageView
android:id="@+id/list_image"
android:contentDescription="@string/app_name"
android:layout_width="100dp"
android:layout_height="100dp"
android:background="@drawable/imagebordercolor"
/>
</LinearLayout>
<!-- Title Of Song-->
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/thumbnail"
android:layout_toRightOf="@+id/thumbnail"
android:textColor="@android:color/white"
android:textSize="15sp"
android:textStyle="bold"
android:typeface="sans" />
<!-- Description -->
<com.fiveytechnologies.bhagavadgita.views.ExpandableTextView
android:id="@+id/expand_text_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/title"
android:focusable="false"
android:focusableInTouchMode="false"
android:layout_marginTop="1dip"
android:layout_toRightOf="@+id/thumbnail"
expandableTextView:maxCollapsedLines="8"
expandableTextView:animAlphaStart="1"
>
<TextView
android:id="@id/expandable_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:textSize="12sp"
android:textColor="@android:color/white" />
<ImageButton
android:id="@id/expand_collapse"
android:contentDescription="@string/app_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="1dp"
android:layout_gravity="right|bottom"
android:background="@android:color/transparent"/>
</com.fiveytechnologies.bhagavadgita.views.ExpandableTextView>
<!-- Rightend Duration -->
<TextView
android:id="@+id/duration"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignTop="@id/title"
android:gravity="right"
android:text="@string/slokacount"
android:layout_marginRight="5dip"
android:textSize="12sp"
android:textColor="#10bcc9"
android:textStyle="bold"
android:visibility="gone"
/>
<!-- Rightend Arrow -->
shit
java.lang.NoClassDefFoundError: com/ms/square/android/expandabletextview/R$styleable
at com.ms.square.android.expandabletextview.ExpandableTextView.init(ExpandableTextView.java:253)
at com.ms.square.android.expandabletextview.ExpandableTextView.(ExpandableTextView.java:95)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.jetbrains.android.uipreview.ViewLoader.createNewInstance(ViewLoader.java:465)
at org.jetbrains.android.uipreview.ViewLoader.loadClass(ViewLoader.java:172)
at org.jetbrains.android.uipreview.ViewLoader.loadView(ViewLoader.java:105)
at com.android.tools.idea.rendering.LayoutlibCallbackImpl.loadView(LayoutlibCallbackImpl.java:186)
at android.view.BridgeInflater.loadCustomView(BridgeInflater.java:334)
at android.view.BridgeInflater.loadCustomView(BridgeInflater.java:345)
at android.view.BridgeInflater.createViewFromTag(BridgeInflater.java:245)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727)
at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:858)
at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:70)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:834)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821)
at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:861)
at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:70)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:834)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821)
at android.view.LayoutInflater.inflate(LayoutInflater.java:518)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:324)
at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:429)
at com.android.ide.common.rendering.LayoutLibrary.createSession(LayoutLibrary.java:389)
at com.android.tools.idea.rendering.RenderTask$2.compute(RenderTask.java:548)
at com.android.tools.idea.rendering.RenderTask$2.compute(RenderTask.java:533)
at com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:966)
at com.android.tools.idea.rendering.RenderTask.createRenderSession(RenderTask.java:533)
at com.android.tools.idea.rendering.RenderTask.lambda$inflate$72(RenderTask.java:659)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
i need collaspe the last few lines of the article, but it collaspe the first few lines of the article,can u help me?
When the TextView have just one line to show, the ExpandableTextView let the possibility to be collapsed. And when click the line is cut in half without possibility to expand.
when user input a lot /n , like
String msg = "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\naaaaaa\n\n\n\n\n\n\n\n\n\n\n\n\n\n"
setText(msg, @nonnull SparseBooleanArray collapsedStatus, int position)
it will not work well
How to reset the collapse-state in a listview?
When listview scrolling up and down, the reused textview's height display not right.
Can provide two public methods to dynamically set the expandDrawable and collapseDrawable ?
I added this line in Textview
On first time -> it displays ellipsis at the end of text But After Expand and again on collapse does not display ellipsis .
So it works only for first time.
I am not able to display Ellipsis on collapse of text.
compile 'com.ms-square:expandableTextView:0.1.4'
error:
Uncaught translation error: java.util.concurrent.ExecutionException: java.lang.OutOfMemoryError: GC overhead limit exceeded
Uncaught translation error: java.util.concurrent.ExecutionException: java.lang.OutOfMemoryError: GC overhead limit exceeded
Uncaught translation error: java.util.concurrent.ExecutionException: java.lang.OutOfMemoryError: GC overhead limit exceeded
Uncaught translation error: java.util.concurrent.ExecutionException: java.lang.OutOfMemoryError: GC overhead limit exceeded
Uncaught translation error: java.util.concurrent.ExecutionException: java.lang.OutOfMemoryError: GC overhead limit exceeded
Uncaught translation error: java.util.concurrent.ExecutionException: java.lang.OutOfMemoryError: GC overhead limit exceeded
6 errors; aborting
Error:Execution failed for task ':app:transformClassesWithDexForOfficialDebug'.
com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'E:\Program Files\Java\jdk1.7.0_71\bin\java.exe'' finished with non-zero exit value 1
Hi Awesome library i was searching for accordian kind of similar library and yours kind intriguingly matched my intuition but i need small tweaks on the lib ui like dropdown animation arrow should face right hand side how can i achieve it. and on clicking a title textview i should be able to expand the textview how can i do this. simple example would be i am looking for this
When I use this view, I found when collapsed, there was no action to collapsed.
After Checking the source code, I put the code:
mCollapsedHeight = getMeasuredHeight();
in to the post method of mTv.
It woks. I am wondering if this is an issue.
点击会失效
When we expand textview, it is not showing last few lines because getRealTextViewHeight function is not giving correct textview height.I think it should be called on the right place.Please look into this.
内容够长的情况下,显示不全,另外给控件设置padding ,margin值会影响内容显示
adding android:textIsSelectable="true"
to the inner TextView
causes weird layout issues when toggling the expanded mode. This is crucial for an app i'm working on right now.
Hi,
I think your library would be more awesome with justification support. Is there any possibility to add this feature? For example by adding one of theese libraries:
a) https://github.com/bluejamesbond/TextJustify-Android
b) https://github.com/navabi/JustifiedTextView
to "com.ms.square.android.expandabletextview.ExpandableTextView" instead of default TextView.
Regards,
Petr M.
The XML Layout is:
<com.ms.square.android.expandabletextview.ExpandableTextView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:expandableTextView="http://schemas.android.com/apk/res-auto"
android:id="@+id/expand_text_view"
android:layout_width="100dp"
android:layout_height="wrap_content"
expandableTextView:animDuration="0"
expandableTextView:maxCollapsedLines="2">
<TextView
android:id="@id/expandable_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#666666"
android:textSize="16sp"/>
<ImageButton
android:id="@id/expand_collapse"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|bottom"
android:background="@android:color/transparent"
android:padding="16dp"/>
</com.ms.square.android.expandabletextview.ExpandableTextView>
in Adapter i do :
`
private SparseBooleanArray favorList2 = new SparseBooleanArray();
public void onBindItemViewHolder(RecyclerView.ViewHolder holder, int position) {
...
threeColumnItemViewHolder.expTv1.setText(stringList.get(2) + stringList.get(2) + stringList.get(2),favorList2,position);
.....
}
`
when i unfold the item the item is Invisible, but when scroll out screen then it visible when it in screen next time
I resolved this by commenting
// for maven central deployment
//apply from: 'https://raw.githubusercontent.com/chrisbanes/gradle-mvn-push/master/gradle-mvn-push.gradle'
in build.gradle of lib module
I checked out your code,and run ,finally found it didn't work(collapse).After debug it ,I found the height is not correct(mCollapsedHeight).here is my solution.
problem code:
if (mCollapsed) { animation = new ExpandCollapseAnimation(this, getHeight(), mCollapsedHeight); } else { animation = new ExpandCollapseAnimation(this, getHeight(), getHeight() + mTextHeightWithMaxLines - mTv.getHeight()); }
//////////////////////////
solution:
if (mCollapsed) { animation = new ExpandCollapseAnimation(this, getHeight(), oldHeight); } else { animation = new ExpandCollapseAnimation(this, getHeight(), getHeight() + mTextHeightWithMaxLines - mTv.getHeight()); oldHeight = getHeight (); }
According to debug, I think that the number of rows that get the textview is incorrect. The number of rows obtained before the super.onMeasure() method is correct (may be 0), but the number of rows obtained after this is less. Up
------------------------------Above from Google Translate, the following is the original----------------------
根据debug,我认为是获取textview的行数不正确导致的,在super.onMeasure()方法之前获取到的行数是正确的(也可能是0),但是在这之后获取到的行数变少了
I am only able to expand the text by tapping on the text itself; nothing happens if I tap the ImageButton. Is this by design?
I'm trying to get some ExpandableTextView
inside an ExpandableListView.
I run into a problem like so:
I've prepared a gif
And a git repo to reproduce the problem:
https://github.com/mendhak/expandable-textview-in-expandable-listview-problem
Is there anything I can do to prevent this, maybe some way of forcing the ETV to collapse in the ELV click handler?
You can try add a button a your demo project, and on the onClickListener you set the dummy_text2 again. like
expTv2.setText(getString(R.string.dummy_text2));
Button bt = (Button) findViewById(R.id.test);
bt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
expTv2.setText(getString(R.string.dummy_text2));
}
});
after the button clicked, (that is the same text is set again after view created and when textview is collapsed), the textview can't expand fully. I found the mMeasuredTextHeight is a wrong value.
may be I can solve this problem.
thank you for your code.
Hi Manabu-GT, I am using a slightly modified version of your library, the only modification I did was to remove the drawable for expand and collapse and replace that with a TextView instead so that it shows Read More and Read Less
When I expand an item in the RecyclerView and scroll down and come back up, I find it collapsed, I also find extra blank spaces scattered everywhere, am I missing something? Also as per the GIF if you notice, it doesn't expand another time. Thanks for your suggestions in advance
I use Intellij Idea for android development. I have not been able to build the app with Gradle. I get this error:
No such property: GROUP for class: org.gradle.api.publication.maven.internal.ant.DefaultGroovyMavenDeployer
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.