すべての行にImageViewとTextViewを含むListViewを作成したいと思います。私はそれを行うことができますが、私は行間の距離を変更することに問題があります。どういうわけか私はそれを変えたと思うが、どうしたらいいかわからない。行間の距離ListView Android
ActorAdapter.java:
ArrayList<Actors> actorList;
LayoutInflater vi;
int Resource;
ViewHolder holder;
public ActorAdapter(Context context, int resource, ArrayList<Actors> objects) {
super(context, resource, objects);
vi = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
Resource = resource;
actorList = objects;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// convert view = design
View v = convertView;
if (v == null) {
holder = new ViewHolder();
v = vi.inflate(Resource, null);
holder.image= (ImageView) v.findViewById(R.id.miniimage);
holder.name = (TextView) v.findViewById(R.id.name);
holder.image.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.d("megnyomtam","a fost");
}
});
holder.name.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.d("megnyomtam","a fost");
}
});
v.setTag(holder);
} else {
holder = (ViewHolder) v.getTag();
}
holder.image.setImageResource(R.drawable.ic_launcher);
new DownloadImageTask(holder.image).execute(actorList.get(position).getImageurl());
holder.name.setText(actorList.get(position).getTitle());
return v;
}
static class ViewHolder {
public ImageView image;
public TextView name;
}
private class DownloadImageTask extends AsyncTask<String, Void, Bitmap> {
ImageView bmImage;
public DownloadImageTask(ImageView bmImage) {
this.bmImage = bmImage;
}
protected Bitmap doInBackground(String... urls) {
String urldisplay = urls[0];
Bitmap mIcon11 = null;
try {
InputStream in = new java.net.URL(urldisplay).openStream();
mIcon11 = BitmapFactory.decodeStream(in);
} catch (Exception e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}
return mIcon11;
}
protected void onPostExecute(Bitmap result) {
bmImage.setImageBitmap(result);
}
}
ActorFragment.java
ArrayList<Actors> actorsList;
ActorAdapter adapter;
ListView listview;
public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.activity_actor,parent, false);
actorsList = new ArrayList<Actors>();
new JSONAsyncTask().execute("http://demo.breona.hu:8080/mobil/mobilService?method=getAllData&appid=ESK");
listview = (ListView)v.findViewById(R.id.list25);
adapter = new ActorAdapter(getActivity().getApplicationContext(), R.layout.listview_row_layout, actorsList);
listview.setAdapter(adapter);
return v;
}
問題は、多分私はあまりにもそのコピーXMLSに隠れています。
listview_row_layout.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:focusableInTouchMode="true"
android:background="@drawable/background">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/rellayout">
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignParentLeft="true"
android:id="@+id/miniimage"
android:src="@drawable/ic_launcher"
android:onClick="onClick"/>
<TextView
android:id="@+id/name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/miniimage"
android:text="Cherry"
android:textColor="#000000"
android:onClick="onClick"/>
</LinearLayout>
activity_actor.xmlここ
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" android:background="#F1F1F1"
tools:context=".MainActivity" >
<ListView
android:id="@+id/list25"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:listitem="@layout/listview_row_layout">
</ListView>
は、私が見てみたいものの絵です: https://www.bignerdranch.com/blog/customizing-android-listview-rows-subclassing/
listview_row_layout.xmlの高さを変更するか、recyclerViewを使用してカスタムデバイダーを追加しようとします。 –
希望の画像を投稿できますか? –
どうすればよいですか?プログラム的に、またはXMLで? listview_row_layout.xmlで何を変更すればよいですか? –