How to add multiple images to listview row with horizontal scroll view

I want to display several representations of the image and text in each line of the list, and the number of lines is not fixed (the number of lines can be selected from the server) How to add horizontal scrolling to each line. I am going to use for a loop for the number of images in the getView method, this is the right way to do this.

My question is how can I inflate the horizontal scroll with views of the images of numbers in a row in the getview method

public View getView(final int position, View convertView, ViewGroup parent) { final ViewHolder viewHolder; viewHolder = new ViewHolder(); // View vi = convertView; //if (vi == null) //{ int Numberofimageview=2; for(int i=0;i<Numberofimageview;i++) { // assume i want to display 2 imageview in every row LayoutInflater inflater = (LayoutInflater) con .getSystemService(Context.LAYOUT_INFLATER_SERVICE); convertView = inflater.inflate(R.layout.my_row_layout, parent, false); viewHolder.title = (TextView) convertView.findViewById(R.id.title); Log.d("myapp", "position" + position); convertView.setTag(viewHolder); // } // else // { // viewHolder=(ViewHolder)convertView.getTag(); // } viewHolder.title.setText(data.get(position)); } return convertView; 

} enter image description here

This is xml for string

 RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="wrap_content" > <ImageView android:id="@+id/wagon" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:src="@drawable/wagon" /> <ImageView android:id="@+id/imageView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/wagon" android:layout_centerVertical="true" android:layout_marginLeft="16dp" android:src="@drawable/video" /> <TextView android:id="@+id/title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBottom="@+id/imageView1" android:layout_marginLeft="33dp" android:layout_toRightOf="@+id/imageView1" android:text="title of file" /> <TextView android:id="@+id/type" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_above="@+id/title" android:layout_alignRight="@+id/title" android:layout_marginBottom="18dp" android:text="type of file" /> 

+4
source share
2 answers

Try turning your relativeLayout into a HorizontalScrollView

 <HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent"> <RelativeLayout>[...]</RelativeLayout> </HorizontalScrollView> 
0
source

Create your own list view. Create an xml file. in the main linear layout of the xml file, an image and a text representation are placed. Make sure that the orientation of the line layout is horizontal. Use this xml file in getview methood

0
source

Source: https://habr.com/ru/post/1488485/


All Articles