2013-10-04 70 views
0

我有这样的代码选择更改图像的大小:安卓:在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

看看这个Tutorial的第10点,了解如何使用您自己的Layout作为ListView项目,并且您可以进行任何您想要的操作。

+0

@ some-web感谢您指导我的相关部分,我是一名初学者的android程序员,这真的帮了我很多。 – Ogen

+0

在启动时遇到同样的问题,只需浏览vogella和adnroid开发者一方(通过谷歌),并继续阅读,你会越来越好! –

0

我认为这不是好办法,做你想做的:) .. 你必须使用服装阵列适配器的..

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