forked from jiajunhui/PlayerBase
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
修复RecyclerView嵌套BaseVideoView设置圆角或设置为圆形后出现滑动方向的尺寸不正确问题并增加示例
- Loading branch information
user
committed
Jan 15, 2021
1 parent
773d892
commit 46340a3
Showing
11 changed files
with
232 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
app/src/main/java/com/kk/taurus/avplayer/adapter/RecyclerBaseVideoContentAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package com.kk.taurus.avplayer.adapter; | ||
|
||
import android.graphics.Rect; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.widget.TextView; | ||
|
||
import androidx.annotation.IdRes; | ||
import androidx.annotation.NonNull; | ||
import androidx.recyclerview.widget.RecyclerView; | ||
|
||
import com.kk.taurus.avplayer.R; | ||
import com.kk.taurus.avplayer.bean.RecyclerBaseVideoBean; | ||
import com.kk.taurus.playerbase.entity.DataSource; | ||
import com.kk.taurus.playerbase.render.AspectRatio; | ||
import com.kk.taurus.playerbase.widget.BaseVideoView; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* @author KaraShokZ (张耀中) | ||
* DESCRIPTION | ||
* @name RecyclerBaseVideoContentAdapter | ||
* @date 2021/01/15 14:48 | ||
*/ | ||
public class RecyclerBaseVideoContentAdapter extends RecyclerView.Adapter<RecyclerBaseVideoContentAdapter.BaseViewHolder> { | ||
|
||
private List<RecyclerBaseVideoBean> dataList; | ||
private BaseVideoView typeLiveVideoBvv; | ||
|
||
public RecyclerBaseVideoContentAdapter(List<RecyclerBaseVideoBean> dataList) { | ||
this.dataList = dataList; | ||
} | ||
|
||
@NonNull | ||
@Override | ||
public BaseViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { | ||
if (viewType == 1){ | ||
return new BaseViewHolder(View.inflate(parent.getContext(), R.layout.activity_recycler_base_video_type_video, null)); | ||
}else { | ||
return new BaseViewHolder(View.inflate(parent.getContext(), R.layout.activity_recycler_base_video_type_item, null)); | ||
} | ||
|
||
} | ||
|
||
@Override | ||
public int getItemViewType(int position) { | ||
return dataList.get(position).itemType; | ||
} | ||
|
||
@Override | ||
public void onBindViewHolder(@NonNull BaseViewHolder holder, int position) { | ||
RecyclerBaseVideoBean bean = dataList.get(position); | ||
if (bean.itemType == 1){ | ||
if (typeLiveVideoBvv == null){ | ||
typeLiveVideoBvv = holder.getView(R.id.activity_recycler_base_video_type_video_bvv); | ||
typeLiveVideoBvv.setOvalRectShape(); | ||
// typeLiveVideoBvv.setRoundRectShape(30); | ||
typeLiveVideoBvv.setAspectRatio(AspectRatio.AspectRatio_MATCH_PARENT); | ||
typeLiveVideoBvv.setDataSource(new DataSource(bean.videoUrl)); | ||
typeLiveVideoBvv.start(); | ||
} | ||
}else { | ||
TextView typeStoreAddressTv = holder.getView(R.id.activity_recycler_base_video_type_item_tv); | ||
typeStoreAddressTv.setText(bean.itemStr); | ||
} | ||
} | ||
|
||
@Override | ||
public int getItemCount() { | ||
return dataList != null ? dataList.size() : 0; | ||
} | ||
|
||
public static class BaseViewHolder extends RecyclerView.ViewHolder { | ||
|
||
private View mItemView; | ||
|
||
public BaseViewHolder(@NonNull View itemView) { | ||
super(itemView); | ||
mItemView = itemView; | ||
} | ||
|
||
public <T extends View> T getView(@IdRes int viewId){ | ||
return mItemView.findViewById(viewId); | ||
} | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
app/src/main/java/com/kk/taurus/avplayer/bean/RecyclerBaseVideoBean.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.kk.taurus.avplayer.bean; | ||
|
||
import com.kk.taurus.avplayer.utils.DataUtils; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* @author KaraShokZ (张耀中) | ||
* DESCRIPTION | ||
* @name RecyclerBaseVideoBean | ||
* @date 2021/01/15 14:51 | ||
*/ | ||
public class RecyclerBaseVideoBean { | ||
|
||
public static final List<RecyclerBaseVideoBean> getItemList(){ | ||
List<RecyclerBaseVideoBean> itemList = new ArrayList<>(); | ||
itemList.add(new RecyclerBaseVideoBean(1)); | ||
for (int i = 0; i < 50; i++){ | ||
itemList.add(new RecyclerBaseVideoBean()); | ||
} | ||
return itemList; | ||
} | ||
public int itemType; | ||
public String videoUrl = DataUtils.VIDEO_URL_09,itemStr = "音乐和艺术如何改变世界"; | ||
|
||
public RecyclerBaseVideoBean(int itemType) { | ||
this.itemType = itemType; | ||
} | ||
|
||
public RecyclerBaseVideoBean() { | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
app/src/main/java/com/kk/taurus/avplayer/ui/RecyclerBaseVideoActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.kk.taurus.avplayer.ui; | ||
|
||
import androidx.appcompat.app.AppCompatActivity; | ||
import androidx.recyclerview.widget.LinearLayoutManager; | ||
import androidx.recyclerview.widget.RecyclerView; | ||
|
||
import android.os.Bundle; | ||
|
||
import com.kk.taurus.avplayer.R; | ||
import com.kk.taurus.avplayer.adapter.RecyclerBaseVideoContentAdapter; | ||
import com.kk.taurus.avplayer.bean.RecyclerBaseVideoBean; | ||
|
||
public class RecyclerBaseVideoActivity extends AppCompatActivity { | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_recycler_base_video); | ||
RecyclerView contentRv = findViewById(R.id.content_rv); | ||
contentRv.setLayoutManager(new LinearLayoutManager(this)); | ||
// contentRv.setLayoutManager(new LinearLayoutManager(this,RecyclerView.HORIZONTAL,false)); | ||
contentRv.setAdapter(new RecyclerBaseVideoContentAdapter(RecyclerBaseVideoBean.getItemList())); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent"> | ||
|
||
<androidx.recyclerview.widget.RecyclerView | ||
android:id="@+id/content_rv" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent"/> | ||
</FrameLayout> |
16 changes: 16 additions & 0 deletions
16
app/src/main/res/layout/activity_recycler_base_video_type_item.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:layout_width="match_parent" | ||
android:layout_height="50dp"> | ||
|
||
<TextView | ||
android:id="@+id/activity_recycler_base_video_type_item_tv" | ||
android:layout_width="wrap_content" | ||
android:layout_height="50dp" | ||
android:text="sdfsdfdfsdf" | ||
android:textSize="16sp"/> | ||
<View | ||
android:layout_width="match_parent" | ||
android:layout_height="1dp" | ||
android:background="#f1f1f1"/> | ||
</FrameLayout> |
16 changes: 16 additions & 0 deletions
16
app/src/main/res/layout/activity_recycler_base_video_type_video.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:layout_width="300dp" | ||
android:layout_height="300dp" | ||
android:background="#def453"> | ||
|
||
<com.kk.taurus.playerbase.widget.BaseVideoView | ||
android:id="@+id/activity_recycler_base_video_type_video_bvv" | ||
android:layout_width="250dp" | ||
android:layout_height="250dp" | ||
android:layout_marginLeft="20dp" | ||
android:layout_marginRight="20dp" | ||
android:layout_marginTop="20dp" | ||
android:layout_marginBottom="20dp" | ||
android:background="#000000"/> | ||
</FrameLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters