被添加的TableRow但不显示

被添加的TableRow但不显示

本文介绍了被添加的TableRow但不显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个小应用程序,需要定期添加到tablelayout表行。每getChildCount()方法的行被添加,但它不显示。任何建议将不胜AP preciated

  TableLayout TBL =(TableLayout)findViewById(R.id.mytbl);
    连续的TableRow =新的TableRow(本);
    LL的LinearLayout =新的LinearLayout(本);
    TextView的txtView =新的TextView(本);
    row.setId(1234);
    row.setLayoutParams(新TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT,TableRow.LayoutParams.WRAP_CONTENT));
    row.setGravity(Gravity.CENTER);
    row.setBackgroundResource(android.R.color.darker_gray);
    LinearLayout.LayoutParams LP =新LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT,LinearLayout.LayoutParams.WRAP_CONTENT,1.0F);
    ll.setId(1589);
    ll.setLayoutParams(LP);
    ll.setOrientation(LinearLayout.VERTICAL);
    ll.setBackgroundResource(R.color.header_background);
    ll.setGravity(Gravity.CENTER);    弦乐味精=示例文本;    txtView.setId(657);
    txtView.setLayoutParams(新的LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
    txtView.setTextColor(R.color.a_color);
    txtView.setBackgroundResource(R.drawable.border_a);
    txtView.setGravity(Gravity.TOP | Gravity.LEFT);
    txtView.setText(MSG);
    ll.addView(txtView);
    row.addView(Ⅱ);
    tbl.addView(行,新TableLayout.LayoutParams(TableLayout.LayoutParams.FILL_PARENT,TableLayout.LayoutParams.WRAP_CONTENT)); //可能与布局添加此PARAMS tl.addView(TR,新TableLayout.LayoutParams(LayoutParams.FILL_PARENT,的LayoutParams。 WRAP_CONTENT));

我试过tbl.RequestLayout()和tbl.Invalidate(),但没有帮助。该表是包裹在一个滚动视图这是我最好的猜测,问题出在哪里。我一直在摆弄这几个小时,以便在正确的方向轻推肯定会有所帮助。

 <滚动型
    机器人:ID =@ + ID / scrVw_lst
    机器人:layout_width =match_parent
    机器人:layout_height =WRAP_CONTENT
     >    < TableLayout
        机器人:ID =@ + ID / MYTBL
        机器人:layout_width =match_parent
        机器人:layout_height =WRAP_CONTENT
        机器人:stretchColumns =*>


解决方案

你有没有运行code在添加行的 TableLayout ?我模拟了一个按钮中点击添加行,我得到0 异常的尴尬鸿沟。

总之,改变的LayoutParams 封闭的LinearLayout 来的 TableRow.LayoutParams (其父是的TableRow

  TableRow.LayoutParams LP =新TableRow.LayoutParams(
            TableRow.LayoutParams.FILL_PARENT,
            TableRow.LayoutParams.WRAP_CONTENT,1.0F);
    ll.setId(1589);
    ll.setLayoutParams(LP)

另外,如果这不能解决问题,尝试添加:

 的android:fillViewport =真

在XML布局中的滚动型标记。

I have a small app that periodically needs a table row added to the tablelayout. Per the getChildCount() method the row is being added but it doesn't display. Any suggestions would be greatly appreciated

    TableLayout tbl = (TableLayout)findViewById(R.id.mytbl);
    TableRow row = new TableRow(this);
    LinearLayout ll = new LinearLayout(this);
    TextView txtView = new TextView(this);


    row.setId(1234);
    row.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT,TableRow.LayoutParams.WRAP_CONTENT));
    row.setGravity(Gravity.CENTER);
    row.setBackgroundResource(android.R.color.darker_gray);


    LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT,1.0f);
    ll.setId(1589);
    ll.setLayoutParams(lp);
    ll.setOrientation(LinearLayout.VERTICAL);
    ll.setBackgroundResource(R.color.header_background);
    ll.setGravity(Gravity.CENTER);

    String msg = "Sample Text";

    txtView.setId(657);
    txtView.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
    txtView.setTextColor(R.color.a_color);
    txtView.setBackgroundResource(R.drawable.border_a);
    txtView.setGravity(Gravity.TOP | Gravity.LEFT);
    txtView.setText(msg);


    ll.addView(txtView);
    row.addView(ll);
    tbl.addView(row,new TableLayout.LayoutParams(TableLayout.LayoutParams.FILL_PARENT, TableLayout.LayoutParams.WRAP_CONTENT));//maybe add this with layout params tl.addView(tr,new TableLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));

i've tried tbl.RequestLayout() and tbl.Invalidate() but no help. The table is wrapped in a scrollview which is my best guess as to where the problem is. I've been tinkering with this for several hours so a nudge in the right direction sure would be helpful

    <ScrollView
    android:id="@+id/scrVw_lst"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
     >

    <TableLayout
        android:id="@+id/mytbl"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:stretchColumns="*">
解决方案

Have you run the code for adding a row in your TableLayout? I've simulated adding a row on a click of a Button and I get a awkward Divide by 0 exception.

Anyway, change the LayoutParams of the enclosing Linearlayout to TableRow.LayoutParams(its parent is the TableRow):

    TableRow.LayoutParams lp = new TableRow.LayoutParams(
            TableRow.LayoutParams.FILL_PARENT,
            TableRow.LayoutParams.WRAP_CONTENT, 1.0f);
    ll.setId(1589);
    ll.setLayoutParams(lp)

Also, if this doesn't solve the problem, try to add:

android:fillViewport="true"

to the ScrollView tag in the xml layout.

这篇关于被添加的TableRow但不显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 12:58