机器人TableLayout标题行 [英] Android TableLayout Header row

查看:87
本文介绍了机器人TableLayout标题行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好了,所以我有这个TableLayout,而其全部数据 - 与所有行的编程方式添加。我已经得到了TableLayout一个Horizo​​ntalScrollView,而这又是在一个滚动型内 - 这给了我滚动水平和垂直方向。我试图现在要做的是一个标题行添加到它不会滚动。我试着移动周围的事物,使我的两个滚动的看法实际上是在TableLayout里面并添加TableRows到Horizo​​ntalScrollView;我的希望是能够再添加滚动的意见之外的标题行。

Okay, so I've got this TableLayout, and its full of data - with all of the rows added programmatically. I've got the TableLayout inside of a HorizontalScrollView, which in turn is inside a ScrollView - this gives me scrolling both horizontally and vertically. What I'm trying to do now is add a header row to it that will not scroll. I've tried moving things around so that both of my scroll views were actually inside of the TableLayout and adding the TableRows to the HorizontalScrollView; my hope was to be able to then add the header row outside of the scroll views.

唯一的其他东西我能想到的是有一个第二个表的布局只是为标题行,但得到的列排队的好像这将是困难的。任何想法?

The only other thing I can think of is having a second table layout just for the header row, but getting the columns to line up seems like it would be difficult. Any ideas?

推荐答案

的一种方法是由另一个TableLayout的行内嵌入TableLayout和推杆头的preceding行如下所示。对准数据和报头需要的报头查看对象和数据的查看对象layout_width属性被设置为相同的倾角值。此外,内TableLayout的视图对象的layout_weight属性必须与其相应的标题匹配。 现在,在下面的XML中,我已放置3 TextViews在内TableLayout在单行以配合列标题。这只是说明如何对齐可以做到的。您可以通过充气的布局,并在运行时将其加入编程方式填充数据。

One approach is by embedding a TableLayout within another TableLayout's row and putting the header in the preceding row as seen below. Aligning the data and the header requires the layout_width property of the header View objects and the data's View objects to be set to the same dip values. Also, the layout_weight property of the inner TableLayout's View objects must match its corresponding header. Now, in the XML below, I have placed 3 TextViews in the inner TableLayout in a single row to match with the column headers. This is just to show how the alignment can be done. You can populate that data programmatically by inflating a layout and adding it at runtime.

<?xml version="1.0" encoding="utf-8"?>
<TableLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent">


  <TableRow>
    <TextView android:text="Name"
        android:layout_width="100dp"        
        android:layout_column="0"
        android:layout_weight="1"/>
    <TextView android:text="Score"
        android:layout_width="30dp"
        android:layout_column="1"
        android:layout_weight="1">
    </TextView>
    <TextView android:text="Level"
        android:layout_width="30dp"
        android:layout_column="2"
        android:layout_weight="1">
    </TextView>
  </TableRow>

    <ScrollView android:layout_height="120dp">      
    <TableLayout android:id="@+id/score_table"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent">          
    <TableRow>
        <TextView android:text="Al"
        android:layout_width="100dp"        
        android:layout_column="0"
        android:layout_weight="1">
        </TextView>
        <TextView android:text="1000"
        android:layout_width="30dp"
        android:layout_column="1"
        android:layout_weight="1">
        </TextView>
        <TextView android:text="2"
        android:layout_width="30dp"
        android:layout_column="2"
        android:layout_weight="1">
        </TextView>
    </TableRow>
  </TableLayout>
  </ScrollView>     
</TableLayout>

这篇关于机器人TableLayout标题行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆