0

セレクター用に次のコードがあります。

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

これは、リストビュー項目をクリックして押したままにするとどのように見えるかの例です...

ここに画像の説明を入力

私の質問は: とにかくその写真を小さくして右に揃えることはできますか?

ありがとうございました。

4

2 に答える 2

2

このチュートリアルのポイント 10 を見て、ListView アイテムに独自のレイアウトを使用する方法を理解してください。必要な操作を行うことができます。

于 2013-10-04T10:55:50.633 に答える
0

I think that Not the good way to do what you want :) .. you have To use Costume Array Adapter for that ..

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

于 2013-10-04T11:04:27.493 に答える