public class PostAdapter extends BaseAdapter {
public LayoutInflater inflater;
public ArrayList<Bitmap> data=new ArrayList<Bitmap>();
public int layout;
public PostAdapter(Context c, int layout, ArrayList<Bitmap> data){
this.inflater=(LayoutInflater)c.getSystemService(c.LAYOUT_INFLATER_SERVICE);
this.data=data;
this.layout=layout;
}
@Override
public int getCount() {
return data.size();
}
@Override
public Object getItem(int position) {
return data.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if(convertView==null){
convertView=inflater.inflate(layout,parent,false);
}
Bitmap bm=data.get(position);
ImageView addList_picture=(ImageView)convertView.findViewById(R.id.addlist_picture);
addList_picture.setImageBitmap(bm);
return convertView;
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="horizontal" android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/addlist_picture"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_margin="5dp"
android:scaleType="fitXY"
app:srcCompat="@color/common_google_signin_btn_text_dark_disabled" />
</LinearLayout>
<HorizontalScrollView
android:id="@+id/h_scroll_picture"
android:layout_width="match_parent"
android:layout_height="50dp"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<ListView
android:id="@+id/h_scroll_listView"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<!--android:listSelector="#39000000"-->
</ListView>
</LinearLayout>
</HorizontalScrollView>
- &GT; scrollView布局
image_uri=data.getData();
try {
// add one bitmap
item.add(MediaStore.Images.Media.getBitmap(this.getContentResolver(),image_uri));
// adapter refresh
postAdapter.notifyDataSetChanged();
} catch (IOException e) {
e.printStackTrace();
}
- &GT;主java
我想水平查找列表。但他们仍然垂直。 位图数据很好地应用于列表中。 你能告诉我吗?
答案 0 :(得分:1)
对于水平滚动,请使用Recycler视图而不是Listview。
将布局管理器设置为水平。使用以下代码
LinearLayoutManager layoutManager
= new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false);
RecyclerView myList = (RecyclerView) findViewById(R.id.my_recycler_view);
myList.setLayoutManager(layoutManager);
或者,如果您想使用Listview,则需要使用如下的库:
com.meetme.android.horizontallistview.HorizontalListView
这将使您的任务更简单
请参阅:
https://github.com/MeetMe/Android-HorizontalListView