与ImageView的和TextView的Android的自定义适配器 [英] Android custom adapter with imageview and textview
本文介绍了与ImageView的和TextView的Android的自定义适配器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用下面的XML布局为我定制的适配器。
I am using the following xml layout for my custom adapter.
<?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/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:src="@drawable/ic_launcher" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
</LinearLayout>
当我吹这个自定义布局(对于一个ListView)TextView的有着较大的差距怎么一回事,因为view.I希望能够表现出以下彼此的TextView和图像视图右侧的形象。我怎么迪做到这一点。
When i inflate this custom layout(for a listview) the textview has a large gap beacuse of the image view.I want to be able to show the textview below one another and the image view to the right. How di i do this.
推荐答案
使用 RelativeLayout的
:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:src="@drawable/ic_launcher" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="@id/imageView1"
android:layout_alignParentLeft="true"
android:text="TextView" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/textView1"
android:layout_toLeftOf="@id/imageView1"
android:layout_alignParentLeft="true"
android:text="TextView" />
</RelativeLayout>
这篇关于与ImageView的和TextView的Android的自定义适配器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文