2013-03-08 73 views
1
在布局部分

我上的Android项目的工作中,我需要设计一个用户界面如下图所示图像 -斯普利特的Android

enter image description here

我需要显示在顶部的一些文字Student App ,那么在下面会有Student的不同对象。假设如果我有10 Students那么每个学生将会有10 rows。并且在每一行左边将会有图像,然后在中间会有一些文字在那里,然后在右边会有另一个three text

我取得了一些进展,我有下面的代码。但它不是我在图像中寻找的方式。

<ImageView 
     android:id="@+id/icon" 
     android:src="@drawable/action_eating" 
     android:layout_width="60dp" 
     android:layout_height="60dp" /> 
<LinearLayout 
     android:orientation="vertical" 
     android:layout_gravity="center_vertical" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="15dp" > 
    <TextView 
      android:id="@+id/text1" 
      android:text="test" 
      android:textColor="#333" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textSize="18sp" /> 
    <TextView 
      android:id="@+id/text2" 
      android:text="test2" 
      android:textColor="#6699CC" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textSize="14sp" /> 
</LinearLayout> 

,我需要作出这样的列表滚动。

任何人都可以帮我解决这个问题吗?谢谢您的帮助。

+0

您是否尝试过使用tableview – DjHacktorReborn 2013-03-08 06:49:59

+0

或可能是'RelativeLayout'? – SudoRahul 2013-03-08 06:50:22

+0

还没有。你们能为我提供一个例子吗? – AKIWEB 2013-03-08 06:51:15

回答

1

使用表格视图如何创建列

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

    <!-- 2 columns --> 
    <TableRow 
     android:id="@+id/tableRow1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:padding="5dip" > 

     <TextView 
      android:id="@+id/textView1" 
      android:text="Column 1" 
      android:textAppearance="?android:attr/textAppearanceLarge" /> 

     <Button 
      android:id="@+id/button1" 
      android:text="Column 2" /> 
    </TableRow> 

    <!-- edittext span 2 column --> 
    <TableRow 
     android:id="@+id/tableRow2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:padding="5dip" > 

     <EditText 
      android:id="@+id/editText1" 
      android:layout_span="2" 
      android:text="Column 1 &amp; 2" /> 
    </TableRow> 

    <!-- just draw a red line --> 
    <View 
     android:layout_height="2dip" 
     android:background="#FF0000" /> 

    <!-- 3 columns --> 
    <TableRow 
     android:id="@+id/tableRow3" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:padding="5dip" > 

     <TextView 
      android:id="@+id/textView2" 
      android:text="Column 1" 
      android:textAppearance="?android:attr/textAppearanceLarge" /> 

     <Button 
      android:id="@+id/button2" 
      android:text="Column 2" /> 

     <Button 
      android:id="@+id/button3" 
      android:text="Column 3" /> 
    </TableRow> 

    <!-- display this button in 3rd column via layout_column(zero based) --> 
    <TableRow 
     android:id="@+id/tableRow4" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:padding="5dip" > 

     <Button 
      android:id="@+id/button4" 
      android:layout_column="2" 
      android:text="Column 3" /> 
    </TableRow> 

    <!-- display this button in 2nd column via layout_column(zero based) --> 
    <TableRow 
     android:id="@+id/tableRow5" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:padding="5dip" > 

     <Button 
      android:id="@+id/button5" 
      android:layout_column="1" 
      android:text="Column 2" /> 
    </TableRow> 

</TableLayout> 
+0

这会扩展吗?假设如果我有15名学生,那么它会扩展15行,可滚动? – AKIWEB 2013-03-08 06:56:00

+0

然后在自定义列表项目中创建列表视图 – DjHacktorReborn 2013-03-08 06:57:15

0

您需要为您的学生名单一个ListView,并创建一个从ArrayAdapter<Student>派生的自定义类并覆盖getView()。学生对象列表被传递给适配器,适配器被传递给ListView。如果你正在为一个班级做这件事,而你的目的是要学习,那么这是熟悉并且对于专业Android开发非常实用的好东西。要获得额外的功劳,请在YouTube上查找YouTube上的视频,名为“WorldView of ListView”,并让您的列表比其他同学更快。

+0

您能否为我提供UI如何构建列表视图的示例?谢谢您的帮助。 – AKIWEB 2013-03-08 06:58:13

+0

将您的ListView添加到您的活动布局,并创建第二个布局来表示列表中的每个项目。在您的适配器的getView方法中,您将充气该项目布局,并完成获取对子控件的引用的工作,并从Student对象上设置适当的数据。具体来说,谷歌的东西,如“android listview自定义适配器”或我的答案中提到的东西的各种组合。我无法为您编写代码,但在线,在博客,开源项目等中有大量的例子。 – Rich 2013-03-08 07:00:52