Android TextView 不填充宽度,为什么?
我有以下布局并调用该布局。在某一时刻,这段完全相同的代码将填充父布局(选项卡)的宽度。现在不行了,我也不明白为什么。它阻止我发布最新版本。欢迎任何和所有的意见。
section_title.xml:
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/seasonTitle"
android:padding="3dip"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textColor="#FFFFFFFF"
android:textSize="14sp"
android:textStyle="bold"
android:maxHeight="26sp"
android:background="#FFCC3333"
/>
这是它的调用方式的片段:
TextView titleTv = (TextView)mInflater.inflate(R.layout.section_title, null);
titleTv.setText(titleText);
mMergeAdapter.addView(titleTv);
谢谢!
I have the following layout and call to that layout. At one point this very same code would fill the width of the parent layout, a tab. Now it does not and I can't figure out why. It is keeping me from releasing my latest version. Any and all input is welcomed.
section_title.xml:
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/seasonTitle"
android:padding="3dip"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textColor="#FFFFFFFF"
android:textSize="14sp"
android:textStyle="bold"
android:maxHeight="26sp"
android:background="#FFCC3333"
/>
Here is a snippet of how it is called:
TextView titleTv = (TextView)mInflater.inflate(R.layout.section_title, null);
titleTv.setText(titleText);
mMergeAdapter.addView(titleTv);
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您像这样在没有父视图的情况下膨胀视图时:
一些
android:layout_*
参数将被丢弃。为了避免这种情况,请使用指定的父视图来扩充视图,但不要将视图附加到父视图。像这样:这应该可以解决您的问题。
When you inflate your view without parent like this:
Some
android:layout_*
parameters are just discarded. In order to avoid this, inflate your view with parent specified, but without attaching view to parent. Like this:This should resolve your issue.