0

Here is my XML. I'm adding the text dynamically and setting it as wrap_content in the XML, but afterwards the textview does not seem to be resizing based on the contained text. I'm using an expandable layout to expand on click from https://github.com/AAkira/ExpandableLayout. I'm assuming one of the parent heights have been set wrong, but I've check pretty much all combinations and nothing seems to be helping. Setting the height as hardcoded (500dp) works perfectly fine. Can anyone help me out? Thanks!

<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:card_view="http://schemas.android.com/tools">

    <ScrollView
        android:layout_height="match_parent"
        android:layout_width="wrap_content"
        android:fillViewport="true">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">

            <android.support.v7.widget.CardView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:id="@+id/cardviewTwitterMessages"
                android:layout_marginBottom="8dp"
                card_view:cardElevation="4dp"
                card_view:cardUseCompatPadding="true"
                card_view:cardCornerRadius="5dp">

                <RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content">

                    <Button
                        android:id="@+id/expandableButton1"
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:background="@color/colorPrimary"
                        android:drawableLeft="@android:drawable/arrow_down_float"
                        android:onClick="expandableButton1"
                        android:paddingRight="10dp"
                        android:text="Recent Tweets"
                        android:textColor="#fff" />

                    <com.github.aakira.expandablelayout.ExpandableRelativeLayout
                        android:id="@+id/expandableLayout1"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_below="@+id/expandableButton1"
                        android:background="#fff"
                        android:padding="16dp"
                        app:ael_duration="400"
                        app:ael_expanded="false"
                        app:ael_interpolator="bounce"
                        app:ael_orientation="vertical">

                        <TextView
                            android:textColorLink="@color/colorPrimary"
                            android:id="@+id/TwitterMessagesText"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:minLines="50"/>
                    </com.github.aakira.expandablelayout.ExpandableRelativeLayout>
                </RelativeLayout>
            </android.support.v7.widget.CardView>
        </LinearLayout>

    </ScrollView>

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        android:layout_margin="@dimen/fab_margin"
        android:src="@android:drawable/ic_input_add"
        android:tint="#fdfdfd" />

</android.support.design.widget.CoordinatorLayout>
Hao Yang
  • 3
  • 4
  • change to < android:layout_height="wrap_content" android:layout_width="match_parent" – Nilabja Sep 09 '16 at 09:00
  • Possible duplicate of [What is the difference between match\_parent and fill\_parent?](http://stackoverflow.com/questions/5761960/what-is-the-difference-between-match-parent-and-fill-parent) – Hao Yang Dec 07 '16 at 01:42

1 Answers1

0

Your TextView is trying to match the parent.
Make it wrap_content instead

<TextView
    android:textColorLink="@color/colorPrimary"
    android:id="@+id/TwitterMessagesText"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:minLines="50"/>

Also, your ScrollView is trying to wrap_content while all the children down to the TextView try to match_parent. This means that the ScrollView is trying to wrap its children when those same children are trying to figure out their parent width (in a chain up to ScrollView).

When you set the width to 500dp on your TextView, all of the upward views inherit that same size (because of their match_parent width) thus working perfectly fine.
On your ScrollView, either match_parent or give it some width so its children adjust to it.

@EDIT

Also, as a matter of clean code, replace your fill_parent with match_parent.
fill_parent was deprecated and replaced with match_parent on API 8
reference here

Community
  • 1
  • 1
Ricardo Vieira
  • 1,738
  • 1
  • 18
  • 26
  • Tried as you suggested, it still refuses to do anything. Could the coordinatorlayout cause these problems? – Hao Yang Sep 09 '16 at 09:36
  • Hardly. The coordinatorLayout works just fine. How do you populate the TextVIew? Through the adapter or through basic textView.setText("asd")? – Ricardo Vieira Sep 09 '16 at 10:02