1

我正在尝试使我的 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") + ")");

    }
}

谢谢!

4

3 回答 3

0

尝试 :

 LinearLayout.LayoutParams Params1 = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
 WatchMovieTitle.setLayoutParams(Params1);
于 2013-07-06T16:45:59.950 回答
0

您可以使用

LayoutParams lp=new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);

或者

LayoutParams lp=new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);

基于您的 textview 的父布局。

于 2013-07-06T16:46:29.813 回答
0

假设您已将 TextView 称为 tv,您可以执行此类操作

tv.setLayoutParams(new ViewGroup.LayoutParams(
        ViewGroup.LayoutParams.FILL_PARENT,
        ViewGroup.LayoutParams.FILL_PARENT));
于 2013-07-06T16:47:27.787 回答