我正在尝试将textView
添加到frameLayout
。 TextView
具有wrap_content
属性,所以它在文本增长时增长。我也有此功能添加到FrameLayout
:将Textview添加到确定位置的FrameLayout中
((FrameLayout) findViewById(R.id.mainLayout)).addView(mEditText);
这是框架布局的XML:
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mainLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</FrameLayout>
TextView的总是出现在屏幕的左上角。我想把它放在中间或顶部中间。如何才能做到这一点?
我看了看在How can I dynamically set the position of view in Android?的答案,他们也没有太大的帮助:(主要是由于崩溃..
谢谢,这是唯一的工作! 将框架布局更改为fill_parent将我的东西废弃,但它不显示在此视图下的视图。 –
而不是fill_parent更好地使用match_parent。 – drdrej
如果你的textview有一个小文本,你也可以在'width'属性中使用'LayoutParams.WRAP_CONTENT'。 –