【问题标题】:android textview auto fit in linearlayoutandroid textview自动适应线性​​布局
【发布时间】:2016-02-05 13:17:49
【问题描述】:

我想在线性布局中调整高度文本大小 但是我的 textsize 非常大,所以我无法在线性布局中适应高度 textsize

所以我找到了一个方法,但它非常复杂

MainActivity.java

LinearLayout linearLayout1 = (LinearLayout)view.findViewById(R.id.linearLayout);
linearLayout1.measure(View.MeasureSpec.UNSPECIFIED,View.MeasureSpec.UNSPECIFIED);
TextView textview = (TextView) view.findViewById(R.id.textview);
textview.setTextSize(TypedValue.COMPLEX_UNIT_PX, linearLayout1.getMeasuredHeight());

activity.xml(垂直)

<LinearLayout
 android:id="@+id/linearlayout"
 android:layout_width="0dp"
 android:layout_height="match_parent"
 android:layout_weight="1"
 android:gravity="center">

     <TextView
        android:id="@+id/textview"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:text="text"

     />
</LinearLayout>

你知道另一种简单的方法吗?

【问题讨论】:

  • 在基于 textview 高度修复文本后在 textview 上使用 viewtreeobserver 以编程方式修复线性布局高度

标签: android xml textview android-linearlayout


【解决方案1】:

如果我理解你的问题是正确的,你可以使用图书馆。例如,可以这样: https://github.com/grantland/android-autofittextview

更新:或使用这个https://github.com/AndroidDeveloperLB/AutoFitTextView

希望对你有帮助。

【讨论】:

    猜你喜欢
    • 2017-03-23
    • 2012-08-27
    • 2020-11-23
    • 1970-01-01
    • 2014-12-24
    • 2011-07-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多