android:layout_marginBottom=“4dp”
android:gravity=“center”
android:text="@string/homeMenuGroup"
android:textColor="@color/white" />
android:id="@+id/cv_menu_home_unpack"
android:layout_width=“match_parent”
android:layout_height=“60dp”
android:layout_marginHorizontal=“6dp”
android:layout_marginTop=“4dp”
app:cardCornerRadius=“8dp”
app:cardElevation=“0dp”>
android:id="@+id/cv_menu_home_game"
android:layout_width=“match_parent”
android:layout_height=“60dp”
android:layout_marginHorizontal=“6dp”
android:layout_marginTop=“4dp”
app:cardCornerRadius=“8dp”
app:cardElevation=“0dp”>
android:id="@+id/cl_home_spike"
android:layout_width=“match_parent”
android:layout_height=“120dp”
android:layout_marginHorizontal=“16dp”
android:layout_marginTop=“10dp”
android:background="@drawable/style_linearlayout_round">
android:id="@+id/cv_home_spike_img"
android:layout_width=“80dp”
android:layout_height=“80dp”
android:layout_gravity=“center”
android:layout_marginStart=“20dp”
app:cardCornerRadius=“8dp”
app:cardElevation=“0dp”
app:layout_constraintBottom_toBottomOf=“parent”
app:layout_constraintEnd_toStartOf="@id/ll_home_spike"
app:layout_constraintStart_toStartOf=“parent”
app:layout_constraintTop_toBottomOf="@id/tv_home_spike">
android:id="@+id/cl_home_coupon"
android:layout_width=“match_parent”
android:layout_height=“140dp”
android:layout_marginHorizontal=“16dp”
android:layout_marginTop=“10dp”
android:background="@drawable/style_linearlayout_round">
android:id="@+id/rv_water_falls_flow"
android:layout_width=“match_parent”
android:layout_height=“wrap_content”
android:layout_marginHorizontal=“16dp”
android:layout_marginTop=“10dp” />
Fragment:同样请忽略无用逻辑
package com.qingnuo.yami.view.home;
import android.content.Context;
import android.content.Intent;
import android.database.Observable;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.GradientDrawable;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import an
droid.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.databinding.DataBindingUtil;
import androidx.databinding.ObservableField;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.StaggeredGridLayoutManager;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;
import com.youth.banner.adapter.BannerImageAdapter;
import com.youth.banner.holder.BannerImageHolder;
import com.youth.banner.indicator.CircleIndicator;
import java.util.ArrayList;
import java.util.List;
public class HomeMenuFragment extends Fragment implements View.onClickListener {
private static final String TAG = “HomeMenuFragment”;
private FragmentMenuHomeBinding menuHomeBinding;
private Context mContext;
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
menuHomeBinding = DataBindingUtil.inflate(inflater, R.layout.fragment_menu_home, container, false);
mContext = getContext();
initView();
return menuHomeBinding.getRoot();
}
private void initView() {
//设置Adapter
HomeWaterFallsFlowAdapter waterFallsFlowAdapter = new HomeWaterFallsFlowAdapter(mContext);
waterFallsFlowAdapter.setList(waterFallsFlowBeanArrayList);
menuHomeBinding.rvWaterFallsFlow.setAdapter(waterFallsFlowAdapter);
// 计算需要高度
ViewGroup.LayoutParams layoutParams = menuHomeBinding.rvWaterFallsFlow.getLayoutParams();
int height = 0;
for (int i = 0; i < waterFallsFlowBeanArrayList.size(); i++) {
if (i % 2 == 0) {
height += 400;
} else if (i % 3 == 0) {
height += 360;
aterFallsFlowAdapter.setList(waterFallsFlowBeanArrayList);
menuHomeBinding.rvWaterFallsFlow.setAdapter(waterFallsFlowAdapter);
// 计算需要高度
ViewGroup.LayoutParams layoutParams = menuHomeBinding.rvWaterFallsFlow.getLayoutParams();
int height = 0;
for (int i = 0; i < waterFallsFlowBeanArrayList.size(); i++) {
if (i % 2 == 0) {
height += 400;
} else if (i % 3 == 0) {
height += 360;
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)