请问大家这是什么情况
1.标题android:layout_below="@id/icon"失效
2.瀑布流显示不全
3.左边空白大,不能显示在正确位置
您的每一个用心回答,都会让这个世界变得更美好一些!
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:background="@color/transparent" android:layout_height="wrap_content"> <androidx.cardview.widget.CardView android:layout_width="match_parent" android:layout_height="match_parent" app:cardUseCompatPadding="true" app:cardCornerRadius="6dp" app:cardElevation="5dp"> <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent"> <ImageView android:id="@+id/comPreview" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:adjustViewBounds="true" android:src="@mipmap/test" /> <TextView android:id="@+id/comName" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/comPreview" android:layout_marginTop="20dp" android:layout_marginBottom="5dp" android:text="标题" android:textColor="@color/black" android:textSize="20sp" /> <TextView android:id="@+id/comPrice" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/comName" android:text="¥0.0" android:textColor="@color/red" /> <TextView android:id="@+id/paidNum" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/comName" android:layout_marginLeft="5dp" android:layout_toRightOf="@id/comPrice" android:text="0人付款" /> <TextView android:id="@+id/comStock" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/comName" android:layout_alignParentRight="true" android:text="库存10000" /> </RelativeLayout> </androidx.cardview.widget.CardView> </RelativeLayout>
public class CategoryPagerPresenterImpl implements ICategoryPagerPresenter { private Map<String, Integer> pageInfo = new HashMap<>(); private static final int DEFAULT_PAGE = 1; private CategoryPagerPresenterImpl(){} private static ICategoryPagerPresenter sInstance = null; public static ICategoryPagerPresenter getInstance(){ if (sInstance == null) { sInstance = new CategoryPagerPresenterImpl(); } return sInstance; } @Override public void getContentByCategory(String categoryTitle, int categoryId) { for (ICategoryPagerCallback callback : callbacks) { if (callback.getCategoryId() == categoryId) { callback.onLoading(); } } //根据分类加载内容 Retrofit retrofit = RetrofitManager.getInstance().getRetrofit(); Api api = retrofit.create(Api.class); Integer targetPage = pageInfo.get(categoryTitle); if (targetPage == null) { targetPage = DEFAULT_PAGE; pageInfo.put(categoryTitle, targetPage); } String shopPagerUrl = UrlUtils.createShopPagerUrl(categoryTitle); LogUtils.d(CategoryPagerPresenterImpl.this, "shop pager url --> " + shopPagerUrl); Call<Commodities> task = api.getCommoditiesByCategory(shopPagerUrl); task.enqueue(new Callback<Commodities>() { @Override public void onResponse(Call<Commodities> call, Response<Commodities> response) { int code = response.code(); LogUtils.d(CategoryPagerPresenterImpl.this, "code --> " + code); if (code == HttpURLConnection.HTTP_OK) { Commodities commodities = response.body(); LogUtils.d(CategoryPagerPresenterImpl.this, "commodities --> " + commodities.toString()); //更新UI handleShopPagerContentResult(commodities, categoryId); } else { handlerNetworkError(categoryId); } } @Override public void onFailure(Call<Commodities> call, Throwable t) { LogUtils.d(CategoryPagerPresenterImpl.this, "onFailure --> " + t.toString()); } }); } private void handlerNetworkError(int categoryId) { for (ICategoryPagerCallback callback : callbacks){ if (callback.getCategoryId() == categoryId) { callback.onError(); } } } /** * 通知UI更新 * @param commodities * @param categoryId */ private void handleShopPagerContentResult(Commodities commodities, int categoryId) { for (ICategoryPagerCallback callback : callbacks){ if (callback.getCategoryId() == categoryId) { if (commodities == null || commodities.getData().size() == 0) { callback.onEmpty(); } else { callback.onContentLoaded(commodities.getData()); } } } } private ArrayList<ICategoryPagerCallback> callbacks = new ArrayList<>(); @Override public void registerCallback(ICategoryPagerCallback callback) { if (!callbacks.contains(callback)) { callbacks.add(callback); } } @Override public void unregisterCallback(ICategoryPagerCallback callback) { callbacks.remove(callback); } }
public class ShopPagerContentAdapter extends RecyclerView.Adapter<ShopPagerContentAdapter.InnerHolder> { List<Commodities.DataBean> mData = new ArrayList<>(); @NonNull @Override public InnerHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_stagger_shop_commodity, parent, false); return new InnerHolder(view); } @Override public void onBindViewHolder(@NonNull InnerHolder holder, int position) { Commodities.DataBean dataBean = mData.get(position); holder.setData(dataBean); } @Override public int getItemCount() { if (mData != null) { return mData.size(); } return 0; } public void setCommodities(List<Commodities.DataBean> commodities) { mData.clear(); mData.addAll(commodities); notifyDataSetChanged(); } public class InnerHolder extends RecyclerView.ViewHolder { @BindView(R.id.comName) public TextView comName; @BindView(R.id.comPrice) public TextView comPrice; @BindView(R.id.comStock) public TextView comStock; @BindView(R.id.paidNum) public TextView paidNum; @BindView(R.id.comPreview) public ImageView comPreview; //找到条目控件 public InnerHolder(@NonNull View itemView) { super(itemView); ButterKnife.bind(this, itemView); } public void setData(Commodities.DataBean dataBean) { comName.setText(dataBean.getComName()); comPrice.setText("¥"+dataBean.getComPrice()); comStock.setText("库存"+dataBean.getComStock()); paidNum.setText(dataBean.getPaidNum()+"人付款"); Glide.with(itemView.getContext()).load(dataBean.getComPreview()).into(comPreview); } } }
失效,应该是写布局有问题。但是没代码,不好分析
问题1 :失效 找不到指定id 或者你这个id在你这个view的下面(相对布局有顺序的)
属性具体查看:https://www.runoob.com/w3cnote/android-tutorial-relativelayout.html
问题2: 是不是数据太少了 没太懂 就像康师傅说的 要代码看看
上代码
失效,应该是写布局有问题。但是没代码,不好分析
问题1 :失效 找不到指定id 或者你这个id在你这个view的下面(相对布局有顺序的)
属性具体查看:https://www.runoob.com/w3cnote/android-tutorial-relativelayout.html
问题2: 是不是数据太少了 没太懂 就像康师傅说的 要代码看看
上代码