在您的情况下,您绝对可以使用ViewPager,但如果我是您,我会选择RecyclerView,其方向设置为LinearLayoutManager,其方向设置为Horizontal,因此您不需要HorizontalScrollView,并使用RecyclerView,您还将获得您正在寻找的adapter 的东西..
现在为了scale 或在click 上显示一些其他效果以区别于其他,您可以Animate 那个特定视图,
我为此编写了一些演示代码,在此处发布所需文件,如果这是您想要的,请告诉我,
活动
/**
* Created by Satyen on 10/27/15.
**/
public class SlidingDrawerActivity extends Activity {
RecyclerView rcyList;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_scroll_list);
rcyList = (RecyclerView) findViewById(R.id.rcyList);
LinearLayoutManager layoutManager = new LinearLayoutManager(this);
layoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
rcyList.setLayoutManager(layoutManager);
/* rcyList.addItemDecoration(
new DividerItemDecoration(this, null));*/
MyRecyclerViewAdapter myRecyclerAdapter = new MyRecyclerViewAdapter(this);
rcyList.setAdapter(myRecyclerAdapter);
}
}
活动布局
<!-- layout_scroll_list.xml -->
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_weight="1">
<android.support.v7.widget.RecyclerView
android:id="@+id/rcyList"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="@android:color/holo_blue_dark"
android:paddingLeft="8dp"
android:paddingRight="8dp" />
</FrameLayout>
</LinearLayout>
适配器
public class MyRecyclerViewAdapter extends RecyclerView.Adapter<MyRecyclerViewAdapter.CustomViewHolder> {
private Context mContext;
View animatedView = null;
public MyRecyclerViewAdapter(Context context) {
this.mContext = context;
}
@Override
public CustomViewHolder onCreateViewHolder(ViewGroup viewGroup, final int i) {
final View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.list_row, null);
CustomViewHolder viewHolder = new CustomViewHolder(view);
/*final Animation a = AnimationUtils.loadAnimation(mContext, R.anim.scale_up);*/
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// You can tweak with the effects here
if (animatedView == null) {
animatedView = view;
} else {
animatedView.setAnimation(null);
animatedView = view;
}
ScaleAnimation fade_in = new ScaleAnimation(1f, 1.3f, 1f, 1.3f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
fade_in.setDuration(100); // animation duration in milliseconds
fade_in.setFillAfter(true); // If fillAfter is true, the transformation that this animation performed will persist when it is finished.
view.startAnimation(fade_in);
}
});
return viewHolder;
}
@Override
public void onBindViewHolder(CustomViewHolder customViewHolder, int i) {
//Setting text view title
customViewHolder.textView.setText("Data No. " + i);
}
@Override
public int getItemCount() {
return 10;
}
public class CustomViewHolder extends RecyclerView.ViewHolder {
protected ImageView imageView;
protected TextView textView;
public CustomViewHolder(View view) {
super(view);
this.imageView = (ImageView) view.findViewById(R.id.thumbnail);
this.textView = (TextView) view.findViewById(R.id.title);
}
}
}
适配器行布局
<!-- list_row.xml -->
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:orientation="vertical">
<RelativeLayout
android:layout_width="80dp"
android:layout_height="match_parent">
<ImageView
android:id="@+id/thumbnail"
android:layout_width="100dp"
android:layout_height="80dp"
android:layout_alignParentLeft="true"
android:layout_centerInParent="true"
android:scaleType="centerCrop"
android:src="@mipmap/ic_launcher" />
<TextView
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/thumbnail"
android:layout_centerHorizontal="true"
android:text="dafdafda"
android:textColor="#222"
android:textSize="12sp" />
</RelativeLayout>
</LinearLayout>
除了你还可以使用TwoWayView,它提供了实现HorizontalListView的功能,
以上只是一些演示代码,可能需要一些调整,如果有帮助请告诉我或进一步询问...
还添加了输出的截图..