모든 행에 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를 사용하고 custom devider를 추가하십시오. –
원하는 이미지를 게시 할 수 있습니까 –
어떻게? 프로그래밍 방식으로 또는 XML로? 그리고 listview_row_layout.xml에서 무엇을 변경해야합니까? –