繁体   English   中英

TableLayout-内联TextView和ImageView

[英]TableLayout - TextView and ImageView inline

我建立了一个将TextViews和ImageViews动态添加到TableLayout中的应用程序。 我面临一个小问题,我无法使ImageView与TextView字段内联显示。 在我的片段中,我从服务器获取了结果并将其显示在布局中。

我已经尝试了几种方法,例如将TextView的重力设置为这样的Center Vertical
我尝试限制文本字段的宽度,但无法正常工作。

    firstRow.setGravity(Gravity.CENTER_VERTICAL);

这是我的行的填充方式:

    businessNameRow.addView(businessNameField);

我正在动态添加集合,每个集合由7个TextView行和每行1个ImageView组成,如下所示:

TableRow firstRow = new TableRow(getActivity().getApplicationContext());
TableRow secondRow = new TableRow(getActivity().getApplicationContext());
TableRow thirdRow = new TableRow(getActivity().getApplicationContext());
TableRow fourthRow = new TableRow(getActivity().getApplicationContext());
TableRow fifthRow = new TableRow(getActivity().getApplicationContext());
TableRow sixthRow = new TableRow(getActivity().getApplicationContext());
TableRow imageRow = new TableRow(getActivity().getApplicationContext());
TableRow seventhRow = new TableRow(getActivity().getApplicationContext());

然后我将行添加到表中

final TableLayout tl = (TableLayout)root.findViewById(R.id.tableResultsGPS);

tl.addView(firstRow); //And so on

我的TableLayout放置在ScrollView中,因此我可以滚动浏览结果列表。

附上我要实现的图像以及现在的图像。 在此处输入图片说明

似乎您要实现的目标更适合ListView实现。

总体思路:

  • 创建具有单个项目布局的列表项目(您的textview和图像)
  • 创建一个新类来为您的每个项目建模
  • 使用列表视图,将数据绑定到ListView。

有很多教程。 尝试这个

旁注:布局选择的好建议是ListView项的相对布局。 我的个人最爱之一,因为它的灵活性。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM