Android TextView在将其layoutparams设置为填充父对象时垂直写入文本
我正在尝试将Android TextView在将其layoutparams设置为填充父对象时垂直写入文本,android,android-layout,textview,Android,Android Layout,Textview,我正在尝试将TextView添加到扩展LinearLayout的视图中。当我将其布局参数的宽度设置为fill\u parent或wrap\u content时,TextView中的文本将垂直显示,如下所示 e、 g 但是,当我将宽度设置为某个固定数字时,它将正常显示或按我的预期显示 e、 g.案文 我的问题是为什么会发生这种情况以及如何解决它,即我应该如何以编程方式设置TextView可以水平写入文本,而无需设置固定的宽度,例如设置fill\u parent或wrap\u content 下面是
TextView
添加到扩展LinearLayout
的视图中。当我将其布局参数的宽度设置为fill\u parent
或wrap\u content
时,TextView
中的文本将垂直显示,如下所示
e、 g
但是,当我将宽度设置为某个固定数字时,它将正常显示或按我的预期显示
e、 g.案文
我的问题是为什么会发生这种情况以及如何解决它,即我应该如何以编程方式设置TextView
可以水平写入文本,而无需设置固定的宽度,例如设置fill\u parent
或wrap\u 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>
线性布局中似乎只有一个项目。请将线性布局的方向设置为“水平”,如下所示:
android:orientation="horizontal"
LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams)ilViewPager.getLayoutParams();
lp.<change-any-values>;
ilViewPager.setLayoutParams(lp);
此外,如果可能,您应该从当前布局获取LayoutParams并进行修改,而不是从头创建新的LayoutParams对象,如下所示:
android:orientation="horizontal"
LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams)ilViewPager.getLayoutParams();
lp.<change-any-values>;
ilViewPager.setLayoutParams(lp);
LinearLayout.LayoutParams lp=(LinearLayout.LayoutParams)ilViewPager.getLayoutParams();
lp。;
ilViewPager.setLayoutParams(lp);
请看这个,它与您的类似。