Также я пытался установить фон моего представления карты, используемого в представлении переработчика, в моем приложении, для этого я сделал следующее
карта xml:
<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView
android:layout_height="120dp"
android:layout_width="200dp"
android:layout_margin="5dp"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
app:cardCornerRadius="5dp">
<LinearLayout
android:id="@+id/home_card_subject"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:textColor="#ffffff"
android:id="@+id/home_card_subject_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="@string/subject_text"
android:textSize="30sp"
android:gravity="bottom|center_horizontal"
android:padding="5dp"
android:layout_weight="70"/>
<TextView
android:textColor="#ffffff"
android:id="@+id/home_card_credits"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="4 credits"
android:gravity="center_horizontal"
android:layout_weight="30"
/>
</LinearLayout
>
</androidx.cardview.widget.CardView>
фрагмент панели управления :
package com.example.app100.ui.home;
public class HomeFragment extends Fragment {
private HomeViewModel homeViewModel;
LinearLayout cardView;
private ArrayList<Subject> subject = new ArrayList<>();
private DatabaseHelper databaseHelper;
public View onCreateView(@NonNull LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {
databaseHelper = new DatabaseHelper(getContext());
populateArrayList();
//homeViewModel = ViewModelProviders.of(this).get(HomeViewModel.class);
View root = inflater.inflate(R.layout.fragment_home, container, false);
cardView = root.findViewById(R.id.home_card_subject);
/*final TextView textView = root.findViewById(R.id.text_home);
homeViewModel.getText().observe(getViewLifecycleOwner(), new Observer<String>() {
@Override
public void onChanged(@Nullable String s) {
textView.setText(s);
}
});*/
Random rand = new Random();
int rand_int1 = rand.nextInt(3);
switch (rand_int1){
case 0:
cardView.setBackgroundResource(R.drawable.gradient_color1);
break;
case 1:
cardView.setBackgroundResource(R.drawable.gradient_color2);
break;
case 2:
cardView.setBackgroundResource(R.drawable.gradient_color3);
break;
}
RecyclerView recyclerView = (RecyclerView) root.findViewById(R.id.home_recyclerview);
recyclerView.setLayoutManager(new LinearLayoutManager(getContext() , LinearLayoutManager.HORIZONTAL , false));
recyclerView.setAdapter(new RecyclerAdapter(subject));
// recycle.setLayoutManager(new GridLayoutManager( getActivity(),2));
// recycle.setAdapter(new RecyclerAdapter(subList));
return root;
}
private void populateArrayList(){
Log.d(TAG , "populating array list");
Cursor data = databaseHelper.getdata();
while(data.moveToNext()){
Subject sub = new Subject(data.getString(0) , data.getInt(1), data.getInt(2),
data.getInt(3), data.getInt(4),data.getInt(5) , data.getInt(6));
subject.add(sub);
}
}
}
, но при этом были получены следующие ошибки:
2020-04-09 12:18:18.142 15575-15575/com.example.app100 E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.app100, PID: 15575
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.LinearLayout.setBackgroundResource(int)' on a null object reference
at com.example.app100.ui.home.HomeFragment.onCreateView(HomeFragment.java:65)
Мне нужен эффект прокрутки, когда нижняя часть прокручивается над верхней частью, как на изображении ниже как на изображении ниже белая часть прокручивает фиолетовую часть, а не прокручивает ее.