我试图让我的 TextView layout_width 填充父抛出代码。 这是我的代码:
TextView WatchMovieTitle;
private void PrintTheMovieAndYear() {
if (CountWords() > 23) {
// this is what im doing wrong
// WatchMovieTitle.setLayoutParams
// (new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
WatchMovieTitle.setText(movieList.get("movieName") + " " + "("
+ movieList.get("movieYear") + ")");
WatchMovieYear.setVisibility(View.GONE);
} else {
WatchMovieYear
.setText(" " + "(" + movieList.get("movieYear") + ")");
}
}
谢谢!
最佳答案
您可以使用
LayoutParams lp=new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
或
LayoutParams lp=new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
基于 TextView 的父布局。
关于java - Android - 如何在代码中使 TextView fill_parent,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17504922/