我可以在Android上使用带有文本视图的列表视图和图像图标吗
我需要一个listview,就像下面的android应用程序一样 因为我不能发布图片,所以应该是这样的我可以在Android上使用带有文本视图的列表视图和图像图标吗,android,image,listview,layout,Android,Image,Listview,Layout,我需要一个listview,就像下面的android应用程序一样 因为我不能发布图片,所以应该是这样的 在这里|一些自由文本 |用户名等 这是你的任务 任务1> 任务2> 任务1和任务2是从数据库中动态提取的列表 我试图用文本视图创建一个列表问题是,我只能得到列表或文本视图,而不能同时得到两者。我甚至尝试过相对布局,在这种情况下,我看到文本重叠 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/a
在这里|一些自由文本 |用户名等
这是你的任务
任务1> 任务2>
任务1和任务2是从数据库中动态提取的列表 我试图用文本视图创建一个列表问题是,我只能得到列表或文本视图,而不能同时得到两者。我甚至尝试过相对布局,在这种情况下,我看到文本重叠
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/g_tracker_layout"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/question1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:autoLink="all"
android:text="@string/question1"
/>
<ListView android:id="@+id/ListView01"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
任何帮助指导都会对实现类似于此的布局非常有帮助
以下是onCreateMethod()中的代码段
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.g_tracker_home);
this.dh=新轨道道(this);
lv1=(ListView)findViewById(R.id.ListView01);
trackerbj=dh.selectAll();
if(trackerbj!=null){
List al=新的ArrayList();
用于(跟踪器对象:跟踪器对象){
al.add(obj.getTrackerName());
}
lv1.setAdapter(新的ArrayAdapter(这个,android.R.layout.simple_list_item_1,al));
}
来自我的一本书,介绍了如何控制列表行的创建,以便您可以混合文本和图像。该摘录中描述的示例项目可以在该书的GitHub存储库中找到
简而言之,对于
ArrayAdapter
,您需要对其进行子类化并覆盖getView()
,以更新文本和图像。尝试以下操作:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/g_tracker_layout"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/question1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:autoLink="all"
android:text="@string/question1"/>
<ListView android:id="@+id/ListView01"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/question1"/>
</RelativeLayout>
我甚至尝试过相对布局,在这种情况下,我看到文本重叠
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/g_tracker_layout"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/question1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:autoLink="all"
android:text="@string/question1"
/>
<ListView android:id="@+id/ListView01"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
这真的很好。在你获得一些专业知识后,你会发现
RelativeLayout
是最好的布局方案之一。在这个简单的例子中,你也可以使用LinearLayout
,但当事情开始变得复杂时,最好使用RelativeLayout
,它非常灵活,可以让你减少f嵌套元素。感谢您的快速响应,我通过您书中的专家从数组中创建了一个列表,这非常有帮助。问题是在屏幕上,我希望有一个列表与其他组件一起显示,我正在扩展Activity类,而不是扩展ListActivity。我的问题与t相同文本与列表重叠,不知怎么搞不懂