如何在回收站视图中覆盖完整的背景色?

问题描述 投票:0回答:2

Image Description is here

enter image description here

我为版式做了Match Parent,但后来分成了几个可滚动部分。我如何填充剩余的底部背景此回收站视图的颜色吗?

这是我的布局代码:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:gravity="center_horizontal"
android:layout_height="wrap_content"
android:id="@+id/teacher_relative">


<LinearLayout
    android:id="@+id/linr"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:layout_margin="6dp"
    android:background="@drawable/selector_item_main_menu"
    android:orientation="vertical">

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:adjustViewBounds="true"
        android:src="@drawable/home_fund_raising" />

    <TextView
        android:id="@+id/textView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:maxLines="1"
        android:shadowColor="#393939"
        android:shadowDx="2.0"
        android:shadowDy="1.0"
        android:shadowRadius="2.0"
        android:text="ZED"
        android:textAlignment="center"
        android:textColor="@android:color/white"
        android:textSize="12sp" />

</LinearLayout>

<TextView
    android:id="@+id/txt_notify"
    android:layout_width="25dp"
    android:layout_height="25dp"
    android:background="@drawable/bg_white_circle"
    android:gravity="center"
    android:layout_marginLeft="77dp"

    android:text="0"
    android:visibility="gone"

    android:textSize="13sp"
    android:textColor="@color/red"
    android:textStyle="bold" />

Java代码:

    recyclerView = findViewById(R.id.recyclerView);
    // set a GridLayoutManager with default vertical orientation and 3 number of columns
    GridLayoutManager gridLayoutManager = new GridLayoutManager(getApplicationContext(),3);
    recyclerView.setLayoutManager(gridLayoutManager);

我正在使用网格布局

适配器类的代码:

 @Override
public void onBindViewHolder(ViewHolder holder, int position) {

    MyTeacherModel myTeacherModel = myTeacherModelsList.get(position);
    holder.imageView.setImageDrawable(mContext.getResources().getDrawable(myTeacherModel.getImages()));
    holder.textView.setText(myTeacherModel.getText());
    holder.teacher_relative.setBackgroundColor(Functions.getBackColor());

}

@Override
public int getItemCount() {
    return myTeacherModelsList.size();
}

class ViewHolder extends  RecyclerView.ViewHolder{
    public TextView textView, txt_notify;
    public ImageView imageView;
    DataModel item;
    public LinearLayout linr;
    RelativeLayout teacher_relative;

    public ViewHolder(View itemView) {
        super(itemView);
        textView = (TextView) itemView.findViewById(R.id.textView);
        imageView = (ImageView) itemView.findViewById(R.id.imageView);
        linr = (LinearLayout) itemView.findViewById(R.id.linr);
        txt_notify = (TextView) itemView.findViewById(R.id.txt_notify);
        teacher_relative = itemView.findViewById(R.id.teacher_relative);
    }
}
android android-recyclerview
2个回答
0
投票

RelativeLayout上设置背景


0
投票

您应该为包含recyclerview的容器视图提供背景。

<?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"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/selector_item_main_menu">


    <androidx.recyclerview.widget.RecyclerView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/menubar"
        android:id="@+id/myRcv"/>

</RelativeLayout>
© www.soinside.com 2019 - 2024. All rights reserved.