Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/apache-kafka/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在android中在tablerow的右侧显示textview_Android_Textview_Tablerow - Fatal编程技术网

如何在android中在tablerow的右侧显示textview

如何在android中在tablerow的右侧显示textview,android,textview,tablerow,Android,Textview,Tablerow,我正在开发一个android应用程序。我需要在tablerow的右侧显示textview,下面是我正在使用的代码,这个代码有什么问题 ScrollView src; src=(ScrollView)findViewById(R.id.scrollView1); TableLayout t1=new TableLayout(context); TableRow.LayoutParams tableRowParams=new TableRow.LayoutParams(TableRow.Layo

我正在开发一个android应用程序。我需要在tablerow的右侧显示textview,下面是我正在使用的代码,这个代码有什么问题

ScrollView src;
src=(ScrollView)findViewById(R.id.scrollView1);

TableLayout t1=new TableLayout(context);

TableRow.LayoutParams tableRowParams=new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT,TableRow.LayoutParams.FILL_PARENT);                        
tableRowParams.gravity=Gravity.RIGHT | Gravity.CENTER_VERTICAL;

for(int i=0;i<count;i++)
{
    TableRow tr=new TableRow(context);
    TextView txt_peron_name=new TextView(context);
    txt_peron_name.setTextColor(Color.BLACK);
    txt_peron_name.setTextSize(15);
    txt_peron_name.setText("Hello");
    //txt_peron_name.setLayoutParams(tableRowParams);
    tr.setBackgroundResource(R.drawable.cc1);
    //tr.setLayoutParams(tableRowParams);
    tr.addView(txt_peron_name);
    t1.addView(tr,tableRowParams);

}// End of For Loop
src.removeAllViews();   

src.addView(t1);

在XML中为文本视图分配重力权限

或以编程方式

txt_peron_name.setGravityGravity.RIGHT

也试试这个


txt_peron_name.setLayoutParamsthis.rowParams//行的布局参数

在XML中为文本视图指定重力

或以编程方式

txt_peron_name.setGravityGravity.RIGHT

也试试这个

txt_peron_name.setLayoutParamsthis.rowParams//您所在行的布局参数

@Hitesh Kamani 试试这个

@希特什·卡马尼 试试这个


我实现了这个代码

ScrollView sv = new ScrollView(StackDemosActivity.this);
TableLayout t1 = new TableLayout(StackDemosActivity.this);

TableRow.LayoutParams tableRowParams = new TableRow.LayoutParams(
        TableRow.LayoutParams.MATCH_PARENT,
        TableRow.LayoutParams.MATCH_PARENT);
tableRowParams.gravity = Gravity.RIGHT | Gravity.CENTER_VERTICAL;

for (int i = 0; i < 25; i++) {
    TableRow tr = new TableRow(StackDemosActivity.this);
    TextView txt_peron_name = new TextView(StackDemosActivity.this);
    txt_peron_name.setTextColor(Color.BLACK);
    txt_peron_name.setTextSize(15);
    txt_peron_name.setText("Hello");
    tr.addView(txt_peron_name);
    tr.setGravity(Gravity.RIGHT);
    t1.addView(tr, tableRowParams);
}// End of For Loop
ll = (LinearLayout) findViewById(R.id.ll);
ll.removeAllViews();
sv.addView(t1);
ll.addView(sv);
我修改了一些代码,比如使用LinearLayout,然后在里面添加ScrollView。所以这是我所做的微小改变

输出


我实现了这个代码

ScrollView sv = new ScrollView(StackDemosActivity.this);
TableLayout t1 = new TableLayout(StackDemosActivity.this);

TableRow.LayoutParams tableRowParams = new TableRow.LayoutParams(
        TableRow.LayoutParams.MATCH_PARENT,
        TableRow.LayoutParams.MATCH_PARENT);
tableRowParams.gravity = Gravity.RIGHT | Gravity.CENTER_VERTICAL;

for (int i = 0; i < 25; i++) {
    TableRow tr = new TableRow(StackDemosActivity.this);
    TextView txt_peron_name = new TextView(StackDemosActivity.this);
    txt_peron_name.setTextColor(Color.BLACK);
    txt_peron_name.setTextSize(15);
    txt_peron_name.setText("Hello");
    tr.addView(txt_peron_name);
    tr.setGravity(Gravity.RIGHT);
    t1.addView(tr, tableRowParams);
}// End of For Loop
ll = (LinearLayout) findViewById(R.id.ll);
ll.removeAllViews();
sv.addView(t1);
ll.addView(sv);
我修改了一些代码,比如使用LinearLayout,然后在里面添加ScrollView。所以这是我所做的微小改变

输出


这是行不通的。我正在动态显示tableLayout并在其中添加行,我希望textview txt\u person\u名称显示在行的右侧。“我该怎么做?”HiteshKamani在加入gru的建议后,代码运行良好,具有适当的重要性。你应该检查你的代码。“我执行得很好,工作也很好。”“ChintanRathod,我被绊倒了。”。你能在这里发布你实现的代码吗?试试这个,我想你没有为你的文本视图指定布局参数,这不起作用。我正在动态显示tableLayout并在其中添加行,我希望textview txt\u person\u名称显示在行的右侧。“我该怎么做?”HiteshKamani在加入gru的建议后,代码运行良好,具有适当的重要性。你应该检查你的代码。“我执行得很好,工作也很好。”“ChintanRathod,我被绊倒了。”。你能在这里发布你实现的代码吗?试试这个,我想你没有为你的文本视图指定布局参数