gpt4 book ai didi

Android - 将我的 UITableView 移植到 android

转载 作者:行者123 更新时间:2023-11-29 02:31:32 25 4
gpt4 key购买 nike

我想将我的 UITableView 移植到我现在正在开发的 Android 应用程序中。我可以使用基本的 android.R.layout.simple_list_item_1 在 android 中创建基本的 ListView 。但是我在使用自定义单元格时遇到了麻烦。这是我的 UITableView 中的自定义单元格:

enter image description here

所以我的问题是:如何在 android 中创建自定义列表项?它应该看起来像我的自定义 UITableViewCell

是否可以使用界面生成器创建列表项?我如何访问单元格的标签和 View ?

另一个问题是:我的 UITableView 中有多个原型(prototype)单元。但据我所知,我只能为整个列表设置一个具有一种布局样式的 ListAdapter 。它是如何工作的?

谢谢!

最佳答案

听起来您走在正确的轨道上,但如果您列出当前从 xml 布局、 Activity (或 fragment )和适配器中获得的内容,情况会好得多。

打包的 simple_list_item_x 用于非常基本的用途——即“简单”。无论如何,我们将使用的 View 是 ImageView(iOS 中的 UIImageView)、TextView(iOS 中的 UILabel)和 View(iOS 中的 UIView)。

除了 View 之外,我们还将使用 2 种不同的布局,LinearLayout 和 RelativeLayout。前者只是将对象放入水平或垂直列表中,而后者允许您相对于容器或 xml 本身中列出的 View 定位 View 。

下面的 XML 是 ListView 项目的布局。您可以通过调用 findViewById(R.id.icon_image); 在您的 fragment 或 Activity 中将 id 替换为正确的 id,从而通过它们的 id (android:id) 访问这些项目。

<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

<ImageView
android:id="@+id/icon_image"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_width="44dp"
android:layout_height="44dp"
android:layout_marginRight="5dp"/>

<LinearLayout
android:id="@+id/text_wrapper"
android:orientation="vertical"
android:layout_centerVertical="true"
android:layout_alignRight="@+id/icon_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content">

<TextView
android:id="@+id/upper_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>

<TextView
android:id="@+id/lower_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>

<View
android:id="@+id/color_view"
android:layout_alignParentRight="true"
android:layout_width="5dp"
android:layout_height="match_parent" />

</RelativeLayout>

关于第二个问题;如果您使用的是 Eclipse 或 Android Studio(推荐),那么当您创建新布局或打开现有布局时,您可以通过 xml(“文本”)或使用设计器(“设计”)查看它由 View 底部的选项卡指定。

关于你的最后一个问题。是的,每个列表只能有一个适配器,这与 iOS 相同。如果您想要多个项目类型(iOS 中的单元格),那么在“getView(...)”方法下的自定义适配器中,您将决定使用哪个 xml 布局(膨胀)。

这是一个很大的话题,如果您对 android 了解不多,可能会显得有些困难。最后,它与 iOS 的概念相同,只是组织方式略有不同。 vogella 有一个关于 ListViews 和适配器的很好的教程/演练(您需要自定义适配器部分)。 Vogella

关于Android - 将我的 UITableView 移植到 android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26803915/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com