android: two issues using Tablerow+TextView in Tablelayout

后端 未结 3 1668
生来不讨喜
生来不讨喜 2020-12-16 03:46

I am using Tablerow+TextView to make a simple view for blog posts and their replies. In each TableRow I put a TextView in. Now I have two issues:

  1. The text w

3条回答
  •  借酒劲吻你
    2020-12-16 04:09

    This isn't really a complete answer, but it really seems like you're doing this the hard way.

    Instead of constructing your TableRows manually, you should set them up in xml like this:

    tablerow.xml:

    
        
    
    

    Prior to your loop, get a reference to a LayoutInflater:

    LayoutInflater inflater = getLayoutInflater();
    

    Then, inside your loop, create an instance of tablerow using the LayoutInflater:

    TableRow row = (TableRow)inflater.inflate(R.layout.tablerow, tl, false);
    TextView content = (TextView)row.findViewById(R.id.content);
    content.setText("this is the content");
    
    tl.addView(row);
    

    This will allow you to set your layout, appearance, layout params in xml making it much easier to read and debug.

    For the scrolling problem, you'll need to add your TableLayout to a ScrollView. Something like this in your xml:

    
        
    
    

提交回复
热议问题