【发布时间】:2016-09-09 08:58:52
【问题描述】:
这是我的 XML。我正在动态添加文本并将其设置为 XML 中的 wrap_content,但之后文本视图似乎没有根据包含的文本调整大小。我正在使用可展开的布局来展开来自https://github.com/AAkira/ExpandableLayout 的点击。 我假设其中一个父高度设置错误,但我检查了几乎所有组合,似乎没有任何帮助。将高度设置为硬编码(500dp)效果很好。谁能帮我吗?谢谢!
<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>
【问题讨论】: