Перепиши на язык Kotlin , а так же добавь параметр в NewInstance , чтобы мы могли…
- User
Перепиши на язык Kotlin , а так же добавь параметр в NewInstance , чтобы мы могли передать название и этого было бы достаточно , чтобы смоздать квадратик Чтобы добавить квадратики с округлыми краями после заголовка и чтобы они появлялись последовательно слева, можно использовать горизонтальный LinearLayout внутри ConstraintLayout. После вызова метода можно программно добавлять новые квадратики в LinearLayout.
Вот измененный код с добавлением квадратиков после заголовка:
<?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout 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="@color/bg" tools:context=".main_Fragments.BlankHomeFragment"> <androidx.cardview.widget.CardView android:id="@+id/cardView" android:layout_width="match_parent" android:layout_height="300dp" app:cardCornerRadius="40dp" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent"> <ImageView android:id="@+id/blankImage" android:layout_width="match_parent" android:layout_height="match_parent" android:adjustViewBounds="true" android:scaleType="centerCrop" /> </androidx.cardview.widget.CardView> <TextView android:id="@+id/Title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginStart="16dp" android:layout_marginTop="28dp" android:text="Enkanto" android:textColor="@color/white" android:textSize="32dp" android:textStyle="bold" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/cardView" /> <LinearLayout android:id="@+id/squaresLayout" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginStart="16dp" android:layout_marginTop="10dp" android:orientation="horizontal" app:layout_constraintStart_toEndOf="@+id/Title" app:layout_constraintTop_toBottomOf="@+id/cardView" /> <TextView android:id="@+id/Runtime" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginStart="16dp" android:layout_marginTop="10dp" android:text="Runtime" android:textColor="@color/white" android:textSize="16dp" android:textStyle="bold" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/squaresLayout" /> <TextView android:id="@+id/Runtime_Timer" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginStart="8dp" android:layout_marginTop="10dp" android:text="1h 22m" android:textColor="@color/silver" android:textSize="16dp" android:textStyle="bold" app:layout_constraintStart_toEndOf="@+id/Runtime" app:layout_constraintTop_toBottomOf="@+id/squaresLayout" /> <TextView android:id="@+id/description" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginStart="232dp" android:layout_marginTop="10dp" android:text="description" android:textColor="@color/white" android:textSize="16dp" android:textStyle="bold" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/squaresLayout" /> </androidx.constraintlayout.widget.ConstraintLayout> - Assistant
package com.example.cinema_provider_app.main_Fragments
import android.graphics.Color import android.graphics.drawable.GradientDrawable import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.ImageView import android.widget.LinearLayout import androidx.fragment.app.Fragment import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView import com.example.cinema_provider_app.R
class BlankHomeFragment : Fragment() {
private lateinit var squaresLayout: LinearLayout override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? ): View? { val view = inflater.inflate(R.layout.fragment_blank_home, container, false) squaresLayout = view.findViewById(R.id.squaresLayout) return view } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) showFragment(R.drawable.historic_7) } private fun showFragment(imageResId: Int) { val imageView = view?.findViewById<ImageView>(R.id.blankImage) imageView?.setImageResource(imageResId) val square = View(requireContext()) square.layoutParams = LinearLayout.LayoutParams(30, 30) val drawable = GradientDrawable() drawable.cornerRadius = 15f drawable.setColor(Color.RED) square.background = drawable squaresLayout.addView(square) } companion object { fun newInstance(imageResId: Int): BlankHomeFragment { val fragment = BlankHomeFragment() val args = Bundle() args.putInt("imageResId", imageResId) fragment.arguments = args return fragment } }