4

我想在列表视图的每一行上显示多个图像视图和文本视图,并且行数不固定(可以从服务器获取整数行数)如何在每一行中添加水平滚动视图。我将在 getView 方法中使用 for 循环来获取 imageview 的数量是否正确。

我的问题是如何在 getview 方法中使用行中的数字图像视图来膨胀水平滚动

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;

} 在此处输入图像描述

这是行的 xml

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

2 回答 2

0

Create a custom listview. Create a xml file. within the main linear layout of the xml file put imageview and textview. Make sure the orientation of the linear layout is horizontal.. Make use of that xml file in getview methood

于 2013-11-12T05:27:17.643 回答
0

尝试将您的 relativeLayout 包含到 Horizo​​ntalScrollView

<HorizontalScrollView 
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent">
<RelativeLayout>[...]</RelativeLayout>
</HorizontalScrollView>
于 2013-06-27T13:19:23.000 回答