如何创建自定义的,Android的ListView控件与 - 图像和文本 [英] What to create Customized-Android-ListView-with-Image-and-Text
本文介绍了如何创建自定义的,Android的ListView控件与 - 图像和文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在Android的。我是新希望使用图片来创建一个listview.By。
我要提上公司的标志标头在页面的顶部。
从那以后,我要重复的列表。
我的XML文件code是这里请建议我更新
<?XML版本=1.0编码=UTF-8&GT?;
<的RelativeLayout的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:背景=@绘制/ list_selector
机器人:方向=横向
机器人:填充=5dip> <! - ListRow左SIED缩略图 - >
<的LinearLayout机器人:ID =@ + ID /缩略图
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:填充=3dip
机器人:layout_alignParentLeft =真
机器人:背景=@绘制/ image_bg
机器人:layout_marginRight =5dip> < ImageView的
机器人:ID =@ + ID / list_image
机器人:layout_width =50dip
机器人:layout_height =50dip
机器人:SRC =@绘制/ ic_launcher/> < / LinearLayout中>
<的TextView
机器人:ID =@ + ID /标题
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_alignTop =@ + ID /缩略图
机器人:layout_toRightOf =@ + ID /缩略图
机器人:文字=酒店
机器人:文字颜色=#040404
机器人:字体=SANS
机器人:TEXTSIZE =15dip
机器人:文字样式=大胆/>
<的TextView
机器人:ID =@ + ID /艺术家
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_below =@ ID /标题
机器人:文字颜色=#343434
机器人:TEXTSIZE =10dip
机器人:layout_marginTop =1dip
机器人:layout_toRightOf =@ + ID /缩略图
机器人:文字=饭店文本/>
< ImageView的机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:SRC =@绘制/箭头
机器人:layout_alignParentRight =真
机器人:layout_centerVertical =真/>< / RelativeLayout的>
解决方案
尝试以下布局
<?XML版本=1.0编码=UTF-8&GT?;
<的RelativeLayout的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:方向=横向
机器人:填充=5dip> <! - ListRow左SIED缩略图 - > < ImageView的
机器人:ID =@ + ID / imgLogo
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
机器人:layout_alignParentLeft =真
机器人:layout_alignParentTop =真
机器人:layout_marginBottom =5DP
机器人:layout_marginRight =5dip
机器人:填充=3dip
机器人:SRC =@绘制/ ic_launcher/> <! - 重复的次数此布局号 - GT&; < RelativeLayout的
机器人:ID =@ + ID / relative1
机器人:layout_width =match_parent
机器人:layout_height =70dp
机器人:layout_below =@ + ID / imgLogo
机器人:layout_marginTop =5DP
机器人:背景=@机器人:彩色/ darker_gray
机器人:重力=center_vertical> < ImageView的
机器人:ID =@ + ID / list_image
机器人:layout_width =50dip
机器人:layout_height =50dip
机器人:layout_alignParentLeft =真
机器人:layout_marginRight =5dip
机器人:填充=3dip
机器人:SRC =@绘制/ ic_launcher/> <的TextView
机器人:ID =@ + ID /标题
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_alignTop =@ + ID / list_image
机器人:layout_marginRight =5DP
机器人:layout_marginTop =10dp
机器人:layout_toLeftOf =@ + ID / imgRight
机器人:layout_toRightOf =@ + ID / list_image
机器人:文字=酒店
机器人:文字颜色=#040404
机器人:TEXTSIZE =15dip
机器人:文字样式=大胆
机器人:字体=SANS/> <的TextView
机器人:ID =@ + ID /艺术家
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_below =@ + ID /标题
机器人:layout_marginRight =5DP
机器人:layout_toLeftOf =@ + ID / imgRight
机器人:layout_toRightOf =@ + ID / list_image
机器人:文字=饭店文本
机器人:文字颜色=#343434
机器人:TEXTSIZE =10dip/> < ImageView的
机器人:ID =@ + ID / imgRight
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_alignParentRight =真
机器人:SRC =@绘制/ ic_launcher/>
< / RelativeLayout的> < RelativeLayout的
机器人:ID =@ + ID / relative2
机器人:layout_width =match_parent
机器人:layout_height =70dp
机器人:layout_below =@ + ID / relative1
机器人:layout_marginTop =5DP
机器人:背景=@机器人:彩色/ darker_gray
机器人:重力=center_vertical> < ImageView的
机器人:ID =@ + ID / list_image
机器人:layout_width =50dip
机器人:layout_height =50dip
机器人:layout_alignParentLeft =真
机器人:layout_marginRight =5dip
机器人:填充=3dip
机器人:SRC =@绘制/ ic_launcher/> <的TextView
机器人:ID =@ + ID /标题
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_alignTop =@ + ID / list_image
机器人:layout_marginRight =5DP
机器人:layout_marginTop =10dp
机器人:layout_toLeftOf =@ + ID / imgRight
机器人:layout_toRightOf =@ + ID / list_image
机器人:文字=酒店
机器人:文字颜色=#040404
机器人:TEXTSIZE =15dip
机器人:文字样式=大胆
机器人:字体=SANS/> <的TextView
机器人:ID =@ + ID /艺术家
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_below =@ + ID /标题
机器人:layout_marginRight =5DP
机器人:layout_toLeftOf =@ + ID / imgRight
机器人:layout_toRightOf =@ + ID / list_image
机器人:文字=饭店文本
机器人:文字颜色=#343434
机器人:TEXTSIZE =10dip/> < ImageView的
机器人:ID =@ + ID / imgRight
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_alignParentRight =真
机器人:SRC =@绘制/ ic_launcher/>
< / RelativeLayout的>< / RelativeLayout的>
I am new in Android .I want to create a listview.By using images.
I want to put on the Header Logo of the Company on the top of the page . After that i want to repeat the list. My XML file Code is here please suggest me the update
<?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="wrap_content"
android:background="@drawable/list_selector"
android:orientation="horizontal"
android:padding="5dip" >
<!-- ListRow Left sied Thumbnail image -->
<LinearLayout android:id="@+id/thumbnail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="3dip"
android:layout_alignParentLeft="true"
android:background="@drawable/image_bg"
android:layout_marginRight="5dip">
<ImageView
android:id="@+id/list_image"
android:layout_width="50dip"
android:layout_height="50dip"
android:src="@drawable/ic_launcher"/>
</LinearLayout>
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/thumbnail"
android:layout_toRightOf="@+id/thumbnail"
android:text="Hotels"
android:textColor="#040404"
android:typeface="sans"
android:textSize="15dip"
android:textStyle="bold"/>
<TextView
android:id="@+id/artist"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/title"
android:textColor="#343434"
android:textSize="10dip"
android:layout_marginTop="1dip"
android:layout_toRightOf="@+id/thumbnail"
android:text="Hotel Text " />
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/arrow"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"/>
</RelativeLayout>
解决方案
Try following layout
<?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="wrap_content"
android:orientation="horizontal"
android:padding="5dip" >
<!-- ListRow Left sied Thumbnail image -->
<ImageView
android:id="@+id/imgLogo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginBottom="5dp"
android:layout_marginRight="5dip"
android:padding="3dip"
android:src="@drawable/ic_launcher" />
<!-- Repeat this layout number of times -->
<RelativeLayout
android:id="@+id/relative1"
android:layout_width="match_parent"
android:layout_height="70dp"
android:layout_below="@+id/imgLogo"
android:layout_marginTop="5dp"
android:background="@android:color/darker_gray"
android:gravity="center_vertical" >
<ImageView
android:id="@+id/list_image"
android:layout_width="50dip"
android:layout_height="50dip"
android:layout_alignParentLeft="true"
android:layout_marginRight="5dip"
android:padding="3dip"
android:src="@drawable/ic_launcher" />
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/list_image"
android:layout_marginRight="5dp"
android:layout_marginTop="10dp"
android:layout_toLeftOf="@+id/imgRight"
android:layout_toRightOf="@+id/list_image"
android:text="Hotels"
android:textColor="#040404"
android:textSize="15dip"
android:textStyle="bold"
android:typeface="sans" />
<TextView
android:id="@+id/artist"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/title"
android:layout_marginRight="5dp"
android:layout_toLeftOf="@+id/imgRight"
android:layout_toRightOf="@+id/list_image"
android:text="Hotel Text "
android:textColor="#343434"
android:textSize="10dip" />
<ImageView
android:id="@+id/imgRight"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:src="@drawable/ic_launcher" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/relative2"
android:layout_width="match_parent"
android:layout_height="70dp"
android:layout_below="@+id/relative1"
android:layout_marginTop="5dp"
android:background="@android:color/darker_gray"
android:gravity="center_vertical" >
<ImageView
android:id="@+id/list_image"
android:layout_width="50dip"
android:layout_height="50dip"
android:layout_alignParentLeft="true"
android:layout_marginRight="5dip"
android:padding="3dip"
android:src="@drawable/ic_launcher" />
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/list_image"
android:layout_marginRight="5dp"
android:layout_marginTop="10dp"
android:layout_toLeftOf="@+id/imgRight"
android:layout_toRightOf="@+id/list_image"
android:text="Hotels"
android:textColor="#040404"
android:textSize="15dip"
android:textStyle="bold"
android:typeface="sans" />
<TextView
android:id="@+id/artist"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/title"
android:layout_marginRight="5dp"
android:layout_toLeftOf="@+id/imgRight"
android:layout_toRightOf="@+id/list_image"
android:text="Hotel Text "
android:textColor="#343434"
android:textSize="10dip" />
<ImageView
android:id="@+id/imgRight"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:src="@drawable/ic_launcher" />
</RelativeLayout>
</RelativeLayout>
这篇关于如何创建自定义的,Android的ListView控件与 - 图像和文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文