我正在尝试添加TextView
到扩展的视图中LinearLayout
。当我将 layoutparams 的宽度设置为fill_parent
orwrap_content
时,里面的文字TextView
会垂直显示,如下所示。
例如
T
E
X
T
但是,当我将宽度设置为某个固定数字时,它将正常显示或按我的预期显示。
例如文本
我的问题是为什么会发生这种情况以及如何解决它,即我应该如何以编程方式设置以便TextView
可以水平书写文本而无需为其设置固定宽度,例如设置fill_parent
或wrap_content
?
ilGallery
这是扩展的父级 XML 代码的设置LinearLayout
:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<com.illib.ilgallery.view.ILGallery
android:id="@+id/galleryLayout"
android:layout_height="fill_parent"
android:layout_width="fill_parent"/>
</LinearLayout>
以下是我如何初始化其中的孩子的代码:
ilViewPager = new ILViewPager(context);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.FILL_PARENT);
ilViewPager.setLayoutParams(params);
ilgallery = this;
//initialize default header and footer view
LinearLayout.LayoutParams params2 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
headerView = new TextView(context);
headerView.setLayoutParams(params2);
((TextView)headerView).setTextSize(TypedValue.COMPLEX_UNIT_PX,40);
((TextView)headerView).setText("hello");
footerView = new TextView(context);
footerView.setLayoutParams(params2);
((TextView)footerView).setTextSize(TypedValue.COMPLEX_UNIT_PX,40);
((TextView)footerView).setText("hello2");