1

I'm trying to make my TextView layout_width to be fill parent throw code. this is my code:

 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") + ")");

    }
}

thanks!

digitalmidges
  • 826
  • 3
  • 13
  • 24

3 Answers3

0

try :

 LinearLayout.LayoutParams Params1 = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
 WatchMovieTitle.setLayoutParams(Params1);
Ciro Santilli OurBigBook.com
  • 347,512
  • 102
  • 1,199
  • 985
Tarsem Singh
  • 14,139
  • 7
  • 51
  • 71
0

You can use

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

or

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

based on your textview's parent layout.

kaushal trivedi
  • 3,405
  • 3
  • 29
  • 47
0

You can do something like this assuming that you have called you TextView as tv

tv.setLayoutParams(new ViewGroup.LayoutParams(
        ViewGroup.LayoutParams.FILL_PARENT,
        ViewGroup.LayoutParams.FILL_PARENT));
Mushtaq Jameel
  • 7,053
  • 7
  • 33
  • 52