Android:更改ListView项目中图像的大小

Android:更改ListView项目中图像的大小,android,listview,Android,Listview,我有一个选择器的代码: <?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <!-- Button Focused--> <item android:state_focused="true" android:state_pressed="false"

我有一个选择器的代码:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Button Focused-->
    <item   android:state_focused="true"
            android:state_pressed="false"
            android:drawable="@drawable/gradient_background"
            />
<!-- Button Focused Pressed-->
    <item   android:state_focused="true"
            android:state_pressed="true"
            android:drawable="@drawable/gradient_background"
            />
<!-- Button Pressed-->
    <item   android:state_focused="false"
            android:state_pressed="true"
            android:drawable="@android:drawable/ic_search_category_default" 
            />
<!-- Button Default Image-->
    <item   android:drawable="@drawable/gradient_background"/>

</selector>

在使用此选择器的活动中,我有:

<ListView
            android:id="@+id/contactsView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_below="@+id/searchButton"
            android:divider="@color/DarkGoldenrod"
            android:dividerHeight="0.1dp"
            android:listSelector="@drawable/list_selector"
            android:drawSelectorOnTop="true" />

现在,这是一个listview项目在单击并按住它时的外观示例

我的问题是:我是否可以把图片缩小并对齐到右边


谢谢。

看看其中的第10点,了解如何为ListView项目使用自己的布局,您可以进行任何您想要的操作。

我认为这不是做您想要的事情的好方法:)。。 为此,您必须使用阵列适配器

public class CustomBookItem extends ArrayAdapter<string>{
ArrayList<string> names;
Context context;
public CustomBookItem(Context context, int textViewResourceId,ArrayList<string> names )
{
    super(context, textViewResourceId, names);
    // TODO Auto-generated constructor stub
    this.names=names;
    this.context=context;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
    // TODO Auto-generated method stub
    View v= convertView;
    LayoutInflater inflater = (LayoutInflater) context
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    v=inflater.inflate(R.layout.custome_listitem, parent,false);
    ImageView imageView = (ImageView) v.findViewById(R.id.icon);
    Textview name=(Textview)v.findViewById(R.id.name);
    imageView.setImageDrawable(r.drawbale.icon_search);
    return v;
}
公共类CustomBookItem扩展了ArrayAdapter{
数组列表名称;
语境;
公共CustomBookItem(上下文、int textViewResourceId、ArrayList名称)
{
super(上下文、textViewResourceId、名称);
//TODO自动生成的构造函数存根
这个名称=名称;
this.context=context;
}
@凌驾
公共视图getView(int位置、视图转换视图、视图组父视图){
//TODO自动生成的方法存根
视图v=转换视图;
LayoutFlater充气器=(LayoutFlater)上下文
.getSystemService(上下文布局\充气机\服务);
v=充气机。充气(R.layout.custome_列表项,父项,false);
ImageView ImageView=(ImageView)v.findViewById(R.id.icon);
Textview name=(Textview)v.findViewById(R.id.name);
imageView.setImageDrawable(r.trable.icon\u搜索);
返回v;
}
R.layout.custome_列表项

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<Textview
    android:id="@+id/icon"
    android:layout_width="0dp"
    android:layout_height="fill_parent"
    android:layout_weight="2" />
<ImageView
    android:id="@+id/icon"
    android:layout_width="0dp"
    android:layout_height="fill_parent"
    android:layout_weight="1" />


@感谢您指导我阅读相关章节,我是一名android程序员初学者,这对我帮助很大。刚开始的时候也遇到了同样的问题,只要浏览vogella和adnroid开发者端(由谷歌提供),继续阅读,你就会越来越好!