【问题标题】:textView.SetText working only when text is longtextView.SetText 仅在文本很长时工作
【发布时间】:2016-05-20 09:51:53
【问题描述】:

由于某些奇怪的原因,setText 仅在文本超过 600 多个字符时才有效... 我从我的数据库中获取文本。

这是代码

private void renderViewDescription() {
    // reference

    final TextView descriptionTextView = (TextView) mRootView.findViewById(R.id.fragment_tour_detail_overview_text);
    // content
    Log.d("Overview: ",mTour.getOverview()); //Text is always ok
    descriptionTextView.setText(mTour.getOverview());
}

XML

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

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:padding="@dimen/global_spacing_xxs"
            android:textAppearance="@style/TextAppearance.CityGuide.Headline"
            android:fontFamily="sans-serif-light"
            android:text="Overview" />

        <View
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="?attr/dividerHorizontal" />


        <TextView
            android:id="@+id/fragment_tour_detail_overview_text"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:padding="@dimen/global_spacing_xxs"
            android:text="Body"
            android:textAppearance="@style/TextAppearance.CityGuide.Body1"
            android:textColor="@color/global_text_secondary"/>
        <View
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="?attr/dividerHorizontal" />


    </LinearLayout>
</android.support.v7.widget.CardView>

When text has many chars it works...

When it's below 500 - 600 it doesn't...

【问题讨论】:

  • 也尝试使用 ScrollView
  • 文本较少时发布屏幕截图
  • mTour.getOverview() 是字符串值吗?
  • @jaydroider 我添加它只是为了美观。 :P
  • 感谢大家抽出宝贵时间帮助我!

标签: java android android-studio textview settext


【解决方案1】:

您需要从Layout 中删除View,因为它与您的正文重叠。

此外,如果您在此处将 android:layout_height="1dp" 设置为您的 View,那么它将起作用。

仅供参考。

<TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:fontFamily="sans-serif-light"
            android:padding="10dp"
            android:singleLine="false"
            android:text="Overview"
            android:textAppearance="?attr/textAppearanceLargePopupMenu"
            android:textColor="#FFF" />

        <!--<View
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="?attr/dividerHorizontal" />-->

        <TextView
            android:id="@+id/fragment_tour_detail_overview_text"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:padding="10dp"
            android:text="OverviewOverviewOverviewOverviewOverviewOverviewOverviewOverviewOverviewOverviewOverviewOverviewO"
            android:textAppearance="?attr/textAppearanceLargePopupMenu"
            android:textColor="#FFF" />

【讨论】:

  • 如果对您有帮助,请接受答案,谢谢:) 在答案的上勾选正确。
猜你喜欢
  • 2015-05-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-09-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-08-13
相关资源
最近更新 更多