【问题标题】:TextView Layout width Change [duplicate]TextView布局宽度更改[重复]
【发布时间】:2018-02-04 03:00:18
【问题描述】:

我想使用 java 将我的 TextView 宽度从 wrap_content 更改为 match_parent。任何人都可以建议一种方法吗?

我目前的自定义TextView如下:

<com.example.app.mytext
                            android:padding="@dimen/lblTime"
                            android:id="@+id/text_quotes"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:background="@android:color/transparent"
                            android:gravity="center"
                            android:textStyle="bold"
                            android:textColor="@color/colorPrimaryDark"
                            android:text="Text"
                            android:textSize="@dimen/newMainText" />

【问题讨论】:

    标签: java android


    【解决方案1】:

    在代码中获取 TextView 后:

    tv.setLayoutParams(new ViewGroup.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));

    【讨论】:

      【解决方案2】:

      只需将此android:layout_width="wrap_content" 更改为android:layout_width="match_parent"

      【讨论】:

      • 我希望它使用 java...不使用 xml
      猜你喜欢
      • 2020-01-30
      • 1970-01-01
      • 2013-11-30
      • 2014-06-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-31
      • 1970-01-01
      相关资源
      最近更新 更多