Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/189.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
android textview设置高度不起作用_Android_Textview_Height - Fatal编程技术网

android textview设置高度不起作用

android textview设置高度不起作用,android,textview,height,Android,Textview,Height,我正在尝试创建一个嵌套线性布局和文本视图的布局,它们垂直放置在线性布局中。它们是按程序创建的。虽然我可以使用布局参数设置线性布局的高度,但对于textview,我无法这样做。使用Textview setLayoutParams或setHeight函数不提供响应。文本总是环绕在内容周围(尽管我在代码中没有提到这一点)。有人能帮我修一下吗?我希望这会有帮助 TextView textView = new TextView(this); textView.setText("Hellow

我正在尝试创建一个嵌套线性布局和文本视图的布局,它们垂直放置在线性布局中。它们是按程序创建的。虽然我可以使用布局参数设置线性布局的高度,但对于textview,我无法这样做。使用Textview setLayoutParams或setHeight函数不提供响应。文本总是环绕在内容周围(尽管我在代码中没有提到这一点)。有人能帮我修一下吗?

我希望这会有帮助

    TextView textView = new TextView(this);
    textView.setText("Hellow World");
    textView.setHeight(prefered_height_in_pixel);
    this.addView(textView)

此代码可能会帮助您:

    LinearLayout.LayoutParams paramsLayoutExpire = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
    TextView txtView=new TextView(this);
    txtView.setLayoutParams(paramsTextViewExpire);
LayoutParams.MATCH\u父项:高度

LayoutParams.WRAP_内容:宽度