在我的片段中,我在一个LinearLayout中有几个TextViews。我在onViewCreated()中动态设置文本。高度由android:layout_height="wrap_content“在XML-Layout中设置。但是,高度不会根据内容进行调整。它们总是保持相同的高度。
下面是XML:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/my_white_color">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/my_white_color"
android:padding="10dp">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/seminarImageView"
android:scaleType="fitCenter"
android:background="@color/gray3"
android:padding="1dp"
android:adjustViewBounds="true"
android:layout_gravity="center_horizontal" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/titelTextView"
android:textColor="@color/blue_heading"
android:textSize="24sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/teaserTextView"
android:textColor="@color/blue1"
android:textSize="18sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/bodyTextView"
android:textColor="@color/blue1"
android:textSize="15sp" />
</LinearLayout>
有什么建议吗?
发布于 2015-12-20 01:14:32
在设置文本后尝试调用requestLayout()。
我不确定,但可以在布局视图之后调用onViewCreated()。
https://stackoverflow.com/questions/34373007
复制相似问题