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

时间:2013-10-04 10:52:33

标签: 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"
            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项目单击并按住它时的样子...

enter image description here

我的问题是:无论如何我可以将那张照片缩小并将其对齐吗?

谢谢。

2 个答案:

答案 0 :(得分:2)

看看这个Tutorial的第10点,了解如何将自己的布局用于ListView项目,并且可以进行任何想要的操作。

答案 1 :(得分:0)

我认为不是做你想要的好方法:) .. 你必须使用Costume Array Adapter ..

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;
}

R.layout.custome_listitem

<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" />

相关问题