recycleview 移动调整 医院详情修改

dev
李桢 2 years ago
parent 914295a798
commit fc92e272a4
  1. 13
      app/src/main/java/com/unionmed/unionmedtv/activity/HospitalActivity.java
  2. 4
      app/src/main/java/com/unionmed/unionmedtv/adapter/HospitalAdapter.java
  3. 1
      app/src/main/java/com/unionmed/unionmedtv/utils/MyGridLayoutManager.java
  4. 39
      app/src/main/res/layout/item_load_more_layout1.xml

@ -6,6 +6,7 @@ import android.os.Bundle;
import android.os.Handler;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.WindowManager;
@ -46,10 +47,12 @@ public class HospitalActivity extends BaseActivity {
private EditText et_search;
private Handler handler = new Handler();
private int selectPostion = 0;//当前列表item点击位置
public static void StartActivity(Context context) {
Intent intent = new Intent(context, HospitalActivity.class);
context.startActivity(intent);
}
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -58,6 +61,7 @@ public class HospitalActivity extends BaseActivity {
initView();
loadData(1);
}
public void initView() {
et_search = findViewById(R.id.et_search);
et_search.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@ -87,14 +91,15 @@ public class HospitalActivity extends BaseActivity {
recyclerView.requestFocus();
recyclerView = findViewById(R.id.recyclerView);
MyGridLayoutManager gridLayoutManager = new MyGridLayoutManager(HospitalActivity.this, numberOfColumns);
gridLayoutManager.setUpView(et_search);
recyclerView.setLayoutManager(gridLayoutManager);
hospitalAdapter = new HospitalAdapter(list, new OnChildClickListener() {
@Override
public <T> void onChildClick(View view, int position, T data) {
selectPostion = position;
GetHospitalApi.MemberBean memberBean = (GetHospitalApi.MemberBean) data;
if(position==list.size()-1){
startNum++;
if (memberBean.isLast()) {
startNum = startNum + endNum;
loadData(0);
} else {
HospitalDetailActivity.StartActivity(HospitalActivity.this, memberBean.getChosCode());
@ -114,6 +119,7 @@ public class HospitalActivity extends BaseActivity {
// ...
}
};
public void loadData(int type) {
EasyHttp.post(HospitalActivity.this)
.api(new GetHospitalApi(et_search.getText().toString(), startNum, CacheUtil.getPkey(), endNum))
@ -136,14 +142,13 @@ public class HospitalActivity extends BaseActivity {
memberBean.setLast(true);
list.add(memberBean);
}
hospitalAdapter.notifyDataSetChanged();
if (type == 0) {
recyclerView.requestFocus();
recyclerView.post(new Runnable() {
@Override
public void run() {
View view = recyclerView.getLayoutManager().findViewByPosition(selectPostion);
View view = recyclerView.getLayoutManager().findViewByPosition(selectPostion - 1);
if (view != null) {
recyclerView.requestFocus();
view.requestFocus();

@ -32,7 +32,7 @@ public class HospitalAdapter extends BaseDelegateMultiAdapter<GetHospitalApi.Mem
@Override
public int getItemType(@NotNull List<? extends GetHospitalApi.MemberBean> data, int position) {
// 根据数据,自己判断应该返回的类型
if (position == data.size()-1) {
if (data.get(position).isLast()) {
return 0;
} else {
return 1;
@ -40,7 +40,7 @@ public class HospitalAdapter extends BaseDelegateMultiAdapter<GetHospitalApi.Mem
}
});
getMultiTypeDelegate()
.addItemType(0, R.layout.item_load_more_layout)
.addItemType(0, R.layout.item_load_more_layout1)
.addItemType(1, R.layout.item_type_hospital_layout);
}

@ -54,6 +54,7 @@ public class MyGridLayoutManager extends GridLayoutManager {
switch (direction) {
case View.FOCUS_DOWN:
currentPosition = currentPosition + getSpanCount();
scrollToPosition(currentPosition);
break;
case View.FOCUS_UP:
if (currentPosition % getSpanCount() == 0 && upView != null) {

@ -0,0 +1,39 @@
<?xml version="1.0" encoding="utf-8"?>
<com.unionmed.unionmedtv.widgets.ImgConstraintLayout 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"
style="@style/FocusStyle"
android:layout_width="396dp"
android:layout_height="222dp"
android:background="@drawable/shape_corners10_color_1b4765">
<ImageView
android:id="@+id/iv_type_three_poster"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:ignore="ContentDescription" />
<RelativeLayout
android:id="@+id/tv"
android:layout_width="396dp"
android:layout_height="222dp">
<TextView
android:id="@+id/tv_load_more"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="点击加载\n更多数据"
android:textSize="21sp"
android:textColor="@color/white_f1f1f1"/>
</RelativeLayout>
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bg_focus_selector"
android:duplicateParentState="true"
android:scaleType="fitXY"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="ContentDescription" />
</com.unionmed.unionmedtv.widgets.ImgConstraintLayout>
Loading…
Cancel
Save