[英]TableLayout - TextView and ImageView inline
I have built an app that dynamically adds TextViews and ImageViews into the TableLayout. 我建立了一个将TextViews和ImageViews动态添加到TableLayout中的应用程序。 I am facing one small issue, I can't get ImageView to be displayed inline with TextView fields.
我面临一个小问题,我无法使ImageView与TextView字段内联显示。 In my fragment I get the results back from a server and display it in the layout.
在我的片段中,我从服务器获取了结果并将其显示在布局中。
I have tried several ways such as setting the gravity of TextView to Center vertical like this 我已经尝试了几种方法,例如将TextView的重力设置为这样的Center Vertical
I tried limiting the width of the text fields but it won't work. 我尝试限制文本字段的宽度,但无法正常工作。
firstRow.setGravity(Gravity.CENTER_VERTICAL);
This is how my rows are populated: 这是我的行的填充方式:
businessNameRow.addView(businessNameField);
I am adding sets dynamically, each set consists of 7 TextView rows and 1 ImageView in each row as follows: 我正在动态添加集合,每个集合由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());
Then I just add the row to the table 然后我将行添加到表中
final TableLayout tl = (TableLayout)root.findViewById(R.id.tableResultsGPS);
tl.addView(firstRow); //And so on
My TableLayout is placed within ScrollView so I can scroll through list of results. 我的TableLayout放置在ScrollView中,因此我可以滚动浏览结果列表。
Attaching image of what I want to achieve and what it looks like now. 附上我要实现的图像以及现在的图像。
Seems like what you are trying to achieve is more suitable with a ListView implementation. 似乎您要实现的目标更适合ListView实现。
The general idea: 总体思路:
There are many tutorials out there. 有很多教程。 Try this
尝试这个
Side Note: Good suggestion for layout choice would be relative layout for your ListView item. 旁注:布局选择的好建议是ListView项的相对布局。 One of my personal favorite because of its flexiblity.
我的个人最爱之一,因为它的灵活性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.