Java 在Android中拆分布局中的部分
我正在做一个Android项目,我需要设计一个用户界面,如下图所示- 我需要在顶部显示一些文本作为Java 在Android中拆分布局中的部分,java,android,android-linearlayout,Java,Android,Android Linearlayout,我正在做一个Android项目,我需要设计一个用户界面,如下图所示- 我需要在顶部显示一些文本作为学生应用程序,然后在下面显示学生的不同对象。假设我有10个学生,那么每个学生将有10行。在每行中都会有图像在左手边,然后在中间会有一些文本出现在右边,然后在右边会有另一个三个文本< /> > 我取得了一些进展,我有以下代码。但这与我在图片中寻找的方式不完全一样 <ImageView android:id="@+id/icon" android:src="@d
学生应用程序
,然后在下面显示学生
的不同对象。假设我有10个学生
,那么每个学生将有10行
。在每行中都会有图像在左手边,然后在中间会有一些文本出现在右边,然后在右边会有另一个<代码>三个文本< /> >
我取得了一些进展,我有以下代码。但这与我在图片中寻找的方式不完全一样
<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>
我需要让列表可以滚动
有人能帮我解决这个问题吗?感谢您的帮助。使用表视图如何创建列
<?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 & 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>
使用表视图如何创建列
<?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 & 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>
您需要学生列表的列表视图,并创建从ArrayAdapter
派生的自定义类,并重写getView()
。学生对象列表将传递给适配器,适配器将传递给ListView。如果你在课堂上这样做,并且你的目的是学习,那么这是一个非常好的东西,可以让你熟悉,并且对于专业的Android开发非常实用。要获得额外的积分,请在YouTube上找到一个来自Google I/O 2012的名为“ListView世界”的视频,使您的列表比其他同学的列表更快。您的学生列表需要一个ListView,并创建一个自定义类,该类派生自ArrayAdapter
并覆盖getView()
。学生对象列表将传递给适配器,适配器将传递给ListView。如果你在课堂上这样做,并且你的目的是学习,那么这是一个非常好的东西,可以让你熟悉,并且对于专业的Android开发非常实用。要获得额外的积分,请在YouTube上找到一个名为“ListView世界”的视频,该视频来自Google I/O 2012,并使您的列表比其他同学更快。您是否尝试过使用TableView,或者可能是RelativeLayout
?还没有。你们能给我举个例子吗?示例。您是否尝试过使用TableView,或者可能是RelativeLayout
?还没有。你们能给我举个例子吗?这是可扩展的吗?假设我有15个学生,那么它将用scrollable展开15行?然后用custom list Item在列表视图中创建这是可展开的吗?假设我有15个学生,那么它将使用scrollable展开15行?然后在列表视图中创建自定义列表项您可以为我提供如何构建该列表视图的UI示例吗?感谢您的帮助。您可以将ListView添加到“活动”布局中,并创建第二个布局来表示列表中的每个项目。在适配器的getView方法中,您将膨胀该项布局,并从Student对象获取对子控件的引用,并在这些子控件上设置适当的数据。具体来说,谷歌的“android listview定制适配器”之类的东西,或者我在回答中提到的各种东西的组合。我无法为您编写代码,但在网上、博客、开源项目等中有大量的示例。您能为我提供如何构建该列表视图的UI示例吗?感谢您的帮助。您可以将ListView添加到“活动”布局中,并创建第二个布局来表示列表中的每个项目。在适配器的getView方法中,您将膨胀该项布局,并从Student对象获取对子控件的引用,并在这些子控件上设置适当的数据。具体来说,谷歌的“android listview定制适配器”之类的东西,或者我在回答中提到的各种东西的组合。我无法为您编写代码,但在网上、博客、开源项目等中有大量的示例。