由于我是Android新手,我正在努力设计一个自定义布局,它将成为我的列表视图行。我喜欢我的列表视图行应该包含标题描述,细节和页脚。我的列表视图行保存着数据,例如我附加的图像。请参阅附件图片Android ListView定制(标题,描述,详细信息,页脚)
0
A
回答
2
你必须要创建your_layout_row.xml先
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="60dp"
android:orientation="horizontal"
android:layout_margin="14dp"
>
<LinearLayout
android:layout_width="60dp"
android:layout_height="60dp"
>
<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:paddingLeft="10dp"
android:layout_height="60dp"
/>
</LinearLayout>
<TextView
android:gravity="center_vertical"
android:paddingBottom="10dp"
android:paddingRight="5dp"
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_gravity="center_vertical"
android:layout_marginLeft="20dp"
android:text="TextView"
android:textStyle="normal|italic"
android:textSize="17dp" />
</LinearLayout>
现在在这里你有你的列表视图布局。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/TaskList_layout_background_color"
>
<ListView
android:id="@+id/lv_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="5dp"
android:dividerHeight="10dp"
android:paddingBottom="5dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="5dp" >
</ListView>
</RelativeLayout>
现在创建类型号
例如:
class ModelClass
{
String text;
public ModelClass(String _text)
{
text = _text;
}
public String getText()
{
return this.text;
}
}
现在在主要活动创建自定义适配器类
public class CustomAdapter extends ArrayAdapter<ModelClass> {
// declaring our ArrayList of items
private ArrayList<ModelClass> objects;
/* here we must override the constructor for ArrayAdapter
* the only variable we care about now is ArrayList<Item> objects,
* because it is the list of objects we want to display.
*/
public CustomAdapter(Context context, int textViewResourceId, ArrayList<ModelClass> objects) {
super(context, textViewResourceId, objects);
this.objects = objects;
}
/*
* we are overriding the getView method here - this is what defines how each
* list item will look.
*/
@Override
public View getView(int position, View convertView, ViewGroup parent){
// assign the view we are converting to a local variable
View v = convertView;
// first check to see if the view is null. if so, we have to inflate it.
// to inflate it basically means to render, or show, the view.
if (v == null) {
LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = inflater.inflate(R.layout.your_layout_row null);
}
/*
* Recall that the variable position is sent in as an argument to this method.
* The variable simply refers to the position of the current object in the list. (The ArrayAdapter
* iterates through the list we sent it)
*
* Therefore, i refers to the current Item object.
*/
ModelClass i = objects.get(position);
if (i != null) {
// This is how you obtain a reference to the TextViews.
// These TextViews are created in the XML files we defined.
TextView tt = (TextView) v.findViewById(R.id.textView);
// check to see if each individual textview is null.
// if not, assign some text!
if (tt != null){
tt.setText(objects.get(position).getText());
}
}
// the view must be returned to our activity
return v;
}
}
现在设置你的ListView适配器连接到本customAdapter。
ArrayList<MyModel> myList = new new ArrayList<MyModel>();
myList.add("1");
myList.add("2");
myList.add("3");
myList.add("4");
ListView myListView = (ListView)findViewById(R.id.lv_list);
CustomAdapter adapter= new CustomAdapter(acitivity, 0, myList);
myListView.setAdapter(adapter);
0
在这种情况下,您必须自定义适配器。
其实Relative相对更适合设计。但是现在我将使用LinearLayout编写简单的代码。
这里是ListView项的自定义布局...
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="30dp"
android:text="Title"
android:background="@android:color/holo_red_light"
android:gravity="center"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="60dp"
android:layout_weight="1"
android:gravity="center"
android:background="@android:color/holo_green_light"
android:text="DESC"/>
<TextView
android:layout_width="0dp"
android:layout_height="60dp"
android:layout_weight="1"
android:gravity="center"
android:background="@android:color/holo_blue_light"
android:text="Other Detais"/>
</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="30dp"
android:text="Footer"
android:background="@android:color/holo_red_light"
android:gravity="center"/>
</LinearLayout>
0
副本和海恩HTET修改上面的回答昂
<TextView
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:text="Title"
android:background="@android:color/holo_red_light"
android:gravity="center"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:padding="20dp"
android:background="@android:color/holo_green_light"
android:text="DESC"/>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:padding="20dp"
android:layout_weight="1"
android:gravity="center"
android:background="@android:color/holo_blue_light"
android:text="Other Detais"/>
</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="15dp"
android:text="Footer"
android:background="@android:color/holo_red_light"
android:gravity="center"/>
相关问题
- 1. Doxygen:空的详细信息描述
- 2. Android主详细信息详细信息
- 3. Magento在onclick链接的产品详细信息页面打开描述标签
- 4. Crystal Reports详细信息详细信息
- 5. 显示来自ListView的详细信息
- 6. Android ListView与详细信息页面null对象
- 7. MSBuild复制命令的详细描述
- 8. 主/详细信息页
- 9. fullCalendar - 事件标题和详细信息
- 10. ASP.net gridview multirow详细信息标题
- 11. Android按钮详细信息
- 12. 指定详细信息表格信息
- 13. 如何让子类指定详细信息,如名称和描述
- 14. 视频文件格式的标题信息的详细信息
- 15. 合作伙伴页面标题和详细信息Crystal Report
- 16. 在php中使用标题和详细信息插入照片标题和详细信息
- 17. 使用带有标题和详细信息的recycleview的Android Cardview
- 18. 的ListView用多张页眉和详细信息节
- 19. 我的详细信息表中的自定义标题
- 20. SugarCRM在详细信息视图中添加其他详细信息图标
- 21. 在产品详细信息页面中添加自定义Metabox(Woo-commerce产品详细信息页面)
- 22. 是否有可能强制Jasper报告标题,组的详细信息和页脚出现在同一页上
- 23. Gridview中分页的详细信息
- 24. Facebook页面详细信息和RESTful API?
- 25. 排序详细信息页面MVC
- 26. 单击图像的详细信息页
- 27. 在Ios中的主详细信息页
- 28. 从DataList到详细信息页面
- 29. 网页错误的详细信息
- 30. Virtuemart 1.1产品详细信息页面
是页脚,页脚或页脚的单元格? – NinjaCoder 2015-02-06 00:46:20
@NinjaCoder页脚持有相应行的日期和时间 – Vrangle 2015-02-06 00:54:07
@Vrangle你有什么试过? – iRuth 2015-02-06 01:13:08