Skip to content

Commit 76b4615

Browse files
author
uis
committed
viewType布局demo
1 parent b9e9bc1 commit 76b4615

4 files changed

Lines changed: 46 additions & 13 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# StackViewLayout
2-
1.支持布局预览、宽高比设置
2+
1.支持布局预览、宽高比设置、viewType布局
33
2.支持自动播放、左右布局
44
3.支持缩放滑动、连续滑动
55

demo/src/main/java/com/uis/stackviewlayout/demo/activity/StackAdapter.java

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -80,22 +80,31 @@ static class StackVH extends RecyclerView.ViewHolder{
8080

8181
@Override
8282
public View onCreateView(ViewGroup parent,int viewType) {
83-
return LayoutInflater.from(parent.getContext()).inflate(R.layout.item_layout,parent,false);
83+
return LayoutInflater.from(parent.getContext()).inflate(
84+
2==viewType?R.layout.item_text:R.layout.item_layout,parent,false);
85+
}
86+
87+
@Override
88+
public int getItemViewType(int position) {
89+
return 2==position?2:0;
8490
}
8591

8692
@Override
8793
public void onBindView(View view, final int position) {
88-
ImageView imageView = view.findViewById(R.id.imageView);
89-
try{
90-
Glide.with(view.getContext()).load(stackData.get(position).getMapImageUrl()).into(imageView);
91-
imageView.setOnClickListener(new View.OnClickListener(){
92-
@Override
93-
public void onClick(View v) {
94-
Log.e("xx","onClicked ..."+position);
95-
}
96-
});
97-
}catch (Exception ex){
98-
ex.printStackTrace();
94+
int viewType = getItemViewType(position);
95+
if(0 == viewType) {
96+
ImageView imageView = view.findViewById(R.id.imageView);
97+
try {
98+
Glide.with(view.getContext()).load(stackData.get(position).getMapImageUrl()).into(imageView);
99+
imageView.setOnClickListener(new View.OnClickListener() {
100+
@Override
101+
public void onClick(View v) {
102+
Log.e("xx", "onClicked ..." + position);
103+
}
104+
});
105+
} catch (Exception ex) {
106+
ex.printStackTrace();
107+
}
99108
}
100109
}
101110

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<shape xmlns:android="http://schemas.android.com/apk/res/android">
3+
<solid android:color="#f00000" />
4+
5+
<corners android:radius="5dp" />
6+
</shape>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:app="http://schemas.android.com/apk/res-auto"
4+
android:layout_width="match_parent"
5+
android:background="@drawable/default_red"
6+
android:layout_height="match_parent">
7+
8+
<TextView
9+
android:layout_width="match_parent"
10+
android:layout_height="wrap_content"
11+
android:layout_gravity="center"
12+
android:textColor="#fff"
13+
android:gravity="center"
14+
android:textSize="25sp"
15+
android:text="StackViewLayout"
16+
/>
17+
18+
</FrameLayout>

0 commit comments

Comments
 (0)