Created
January 15, 2023 18:41
-
-
Save ikhlaqmalik13/b62d160842c8af801cf6b18dcf149eca to your computer and use it in GitHub Desktop.
Dynamically Adding rows in LinearLayout of Surfers stories and Surfers Posts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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" | |
tools:context=".learning.SurferFirstActivity"> | |
<ImageView | |
android:id="@+id/imageView12" | |
android:layout_width="34dp" | |
android:layout_height="34dp" | |
android:layout_marginStart="12dp" | |
android:layout_marginTop="12dp" | |
android:src="@drawable/ic_baseline_sort_24" | |
app:layout_constraintStart_toStartOf="parent" | |
app:layout_constraintTop_toTopOf="parent" | |
app:tint="@color/black" /> | |
<ImageView | |
app:tint="@color/black" | |
android:id="@+id/imageView13" | |
android:layout_width="34dp" | |
android:layout_height="34dp" | |
android:layout_marginEnd="12dp" | |
android:layout_marginTop="10dp" | |
app:layout_constraintEnd_toEndOf="parent" | |
app:layout_constraintTop_toTopOf="parent" | |
app:srcCompat="@drawable/ic_baseline_search_24" /> | |
<TextView | |
android:id="@+id/textView7" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:text="Surfers" | |
android:textColor="@color/black" | |
android:textSize="24sp" | |
android:textStyle="bold" | |
app:layout_constraintBottom_toBottomOf="@+id/imageView12" | |
app:layout_constraintEnd_toStartOf="@+id/imageView13" | |
app:layout_constraintStart_toEndOf="@+id/imageView12" | |
app:layout_constraintTop_toTopOf="@+id/imageView12" /> | |
<HorizontalScrollView | |
android:id="@+id/horizontalScrollView2" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:layout_marginVertical="@dimen/_14dp" | |
android:paddingHorizontal="12dp" | |
android:scrollbars="none" | |
app:layout_constraintEnd_toEndOf="parent" | |
app:layout_constraintStart_toStartOf="parent" | |
app:layout_constraintTop_toBottomOf="@+id/textView7"> | |
<LinearLayout | |
android:id="@+id/ll_surfer_stories" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:orientation="horizontal"> | |
<!-- <de.hdodenhof.circleimageview.CircleImageView--> | |
<!-- android:layout_width="70dp"--> | |
<!-- android:layout_height="70dp"--> | |
<!-- android:layout_marginHorizontal="8dp"--> | |
<!-- android:src="@drawable/dev_amaar"--> | |
<!-- app:civ_border_color="#2196F3"--> | |
<!-- app:civ_border_width="3dp" />--> | |
<!-- <de.hdodenhof.circleimageview.CircleImageView--> | |
<!-- android:layout_width="70dp"--> | |
<!-- android:layout_height="70dp"--> | |
<!-- android:layout_marginHorizontal="8dp"--> | |
<!-- android:src="@drawable/founder_ikhlaq"--> | |
<!-- app:civ_border_color="#987CDC"--> | |
<!-- app:civ_border_width="3dp" />--> | |
<!-- <de.hdodenhof.circleimageview.CircleImageView--> | |
<!-- android:layout_width="70dp"--> | |
<!-- android:layout_height="70dp"--> | |
<!-- android:layout_marginHorizontal="8dp"--> | |
<!-- android:src="@drawable/dev_amaar"--> | |
<!-- app:civ_border_color="#F3217C"--> | |
<!-- app:civ_border_width="3dp" />--> | |
<!-- <de.hdodenhof.circleimageview.CircleImageView--> | |
<!-- android:layout_width="70dp"--> | |
<!-- android:layout_height="70dp"--> | |
<!-- android:layout_marginHorizontal="8dp"--> | |
<!-- android:src="@drawable/founder_ikhlaq"--> | |
<!-- app:civ_border_color="#40F321"--> | |
<!-- app:civ_border_width="3dp" />--> | |
<!-- <de.hdodenhof.circleimageview.CircleImageView--> | |
<!-- android:layout_width="70dp"--> | |
<!-- android:layout_height="70dp"--> | |
<!-- android:layout_marginHorizontal="8dp"--> | |
<!-- android:src="@drawable/dev_amaar"--> | |
<!-- app:civ_border_color="#2196F3"--> | |
<!-- app:civ_border_width="3dp" />--> | |
<!-- <de.hdodenhof.circleimageview.CircleImageView--> | |
<!-- android:layout_width="70dp"--> | |
<!-- android:layout_height="70dp"--> | |
<!-- android:layout_marginHorizontal="8dp"--> | |
<!-- android:src="@drawable/dev_amaar"--> | |
<!-- app:civ_border_color="#2196F3"--> | |
<!-- app:civ_border_width="3dp" />--> | |
</LinearLayout> | |
</HorizontalScrollView> | |
<androidx.core.widget.NestedScrollView | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
app:layout_constraintEnd_toEndOf="parent" | |
app:layout_constraintStart_toStartOf="parent" | |
app:layout_constraintTop_toBottomOf="@+id/horizontalScrollView2"> | |
<LinearLayout | |
android:id="@+id/ll_surfer_posts" | |
android:orientation="vertical" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content"> | |
<!-- <include layout="@layout/row_single_surfer_post" />--> | |
<!-- <include layout="@layout/row_single_surfer_post" />--> | |
<!-- <include layout="@layout/row_single_surfer_post" />--> | |
<!-- <include layout="@layout/row_single_surfer_post" />--> | |
</LinearLayout> | |
</androidx.core.widget.NestedScrollView> | |
</androidx.constraintlayout.widget.ConstraintLayout> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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" | |
app:cardCornerRadius="30dp" | |
android:background="@drawable/bg_top_right_rounded_corner" | |
android:layout_marginVertical="@dimen/_12dp" | |
android:layout_marginHorizontal="@dimen/_12dp" | |
android:paddingVertical="@dimen/_10dp" | |
android:paddingHorizontal="@dimen/_12dp" | |
android:layout_height="280dp"> | |
<androidx.constraintlayout.widget.ConstraintLayout | |
android:layout_width="match_parent" | |
android:layout_height="280dp"> | |
<com.google.android.material.imageview.ShapeableImageView | |
app:shapeAppearance="@style/surfer_top_cornered_radius" | |
android:scaleType="centerCrop" | |
android:id="@+id/iv_post_image" | |
android:layout_width="wrap_content" | |
android:layout_height="280dp" | |
app:layout_constraintBottom_toBottomOf="parent" | |
app:layout_constraintEnd_toEndOf="parent" | |
app:layout_constraintStart_toStartOf="parent" | |
app:layout_constraintTop_toTopOf="parent" | |
app:srcCompat="@drawable/dev_amaar" /> | |
<de.hdodenhof.circleimageview.CircleImageView | |
android:id="@+id/civ_surfer" | |
android:layout_width="60dp" | |
android:layout_height="60dp" | |
android:layout_marginStart="12dp" | |
android:layout_marginTop="8dp" | |
android:src="@drawable/founder_ikhlaq" | |
app:civ_border_color="#2196F3" | |
app:civ_border_width="3dp" | |
app:layout_constraintStart_toStartOf="parent" | |
app:layout_constraintTop_toTopOf="parent" /> | |
<TextView | |
android:textColor="@color/black" | |
android:textStyle="bold" | |
android:id="@+id/tv_post_by" | |
android:textSize="18sp" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_marginStart="12dp" | |
android:layout_marginTop="8dp" | |
android:text="Amaar Amin Bhat" | |
app:layout_constraintStart_toEndOf="@+id/civ_surfer" | |
app:layout_constraintTop_toTopOf="@+id/civ_surfer" /> | |
<TextView | |
android:id="@+id/tv_posted_on" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:text="2 hrs ago" | |
app:layout_constraintStart_toStartOf="@+id/tv_post_by" | |
app:layout_constraintTop_toBottomOf="@+id/tv_post_by" /> | |
<ImageView | |
android:id="@+id/imageView15" | |
android:layout_width="30dp" | |
android:layout_height="30dp" | |
android:layout_marginTop="18dp" | |
app:layout_constraintEnd_toEndOf="@+id/civ_surfer" | |
app:layout_constraintStart_toStartOf="@+id/civ_surfer" | |
app:layout_constraintTop_toBottomOf="@+id/civ_surfer" | |
app:srcCompat="@drawable/ic_baseline_heart_broken_24" | |
app:tint="@color/black" /> | |
<TextView | |
android:id="@+id/tv_like_count" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:text="1.2k" | |
android:textColor="@color/black" | |
android:layout_marginStart="10dp" | |
app:layout_constraintBottom_toBottomOf="@+id/imageView15" | |
app:layout_constraintStart_toEndOf="@+id/imageView15" | |
app:layout_constraintTop_toTopOf="@+id/imageView15" /> | |
<ImageView | |
android:id="@+id/imageView16" | |
android:layout_width="30dp" | |
android:layout_height="30dp" | |
android:layout_marginTop="10dp" | |
app:tint="@color/black" | |
app:layout_constraintEnd_toEndOf="@+id/imageView15" | |
app:layout_constraintStart_toStartOf="@+id/imageView15" | |
app:layout_constraintTop_toBottomOf="@+id/imageView15" | |
app:srcCompat="@drawable/ic_baseline_bookmark_24" /> | |
<com.google.android.material.floatingactionbutton.FloatingActionButton | |
android:id="@+id/floatingActionButton" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_marginBottom="20dp" | |
android:layout_marginStart="16dp" | |
android:backgroundTint="@color/white" | |
android:clickable="true" | |
android:contentDescription="@string/_0" | |
android:focusable="true" | |
android:padding="0dp" | |
app:layout_constraintBottom_toBottomOf="@+id/iv_post_image" | |
app:layout_constraintStart_toStartOf="parent" | |
app:maxImageSize="@dimen/_44dp" | |
app:srcCompat="@drawable/ic_baseline_play_arrow_24" | |
app:tint="@color/black" /> | |
<LinearLayout | |
android:id="@+id/linearLayout4" | |
android:layout_width="0dp" | |
android:layout_height="103dp" | |
android:layout_marginBottom="10dp" | |
android:layout_marginEnd="12dp" | |
android:layout_marginStart="12dp" | |
android:orientation="vertical" | |
app:layout_constraintBottom_toBottomOf="parent" | |
app:layout_constraintEnd_toEndOf="parent" | |
app:layout_constraintStart_toEndOf="@+id/floatingActionButton" | |
app:layout_constraintTop_toTopOf="@+id/floatingActionButton" | |
app:layout_constraintVertical_bias="0.0"> | |
<TextView | |
android:id="@+id/tv_post_title" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:text="Considered as the pro father of pro surfing, don't compare him" | |
android:textColor="@color/white" | |
android:textSize="22sp" | |
android:textStyle="bold" /> | |
<TextView | |
android:id="@+id/tv_location" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:text="Akhran, Mir Bazar" | |
android:textAllCaps="true" | |
android:textColor="@color/white" | |
android:textSize="16sp" /> | |
</LinearLayout> | |
</androidx.constraintlayout.widget.ConstraintLayout> | |
</RelativeLayout> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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="70dp" | |
android:layout_height="70dp"> | |
<de.hdodenhof.circleimageview.CircleImageView | |
android:id="@+id/civ_story" | |
android:layout_width="70dp" | |
android:layout_height="70dp" | |
android:layout_marginHorizontal="8dp" | |
android:src="@drawable/founder_ikhlaq" | |
app:civ_border_color="#987CDC" | |
app:civ_border_width="3dp" /> | |
</RelativeLayout> | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.maple.kashin.learning | |
import android.content.Intent | |
import androidx.appcompat.app.AppCompatActivity | |
import android.os.Bundle | |
import android.widget.Toast | |
import com.bumptech.glide.Glide | |
import com.maple.kashin.databinding.ActivitySurferFirstBinding | |
import com.maple.kashin.databinding.RowSingleSurferPostBinding | |
import com.maple.kashin.databinding.RowSingleSurferStoryBinding | |
class SurferPost( | |
val profilePicUrl: String?, | |
val postUrl: String?, | |
val name: String?, | |
val postedOn: String?, | |
val likeCount: Int?, | |
val title: String?, | |
val location: String?, | |
) | |
class Story( | |
val storyUrl: String? | |
) | |
class SurferFirstActivity : AppCompatActivity() { | |
private lateinit var binding: ActivitySurferFirstBinding | |
private var posts: ArrayList<SurferPost> = arrayListOf<SurferPost>() | |
private var stories: ArrayList<Story> = arrayListOf<Story>() | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
binding = ActivitySurferFirstBinding.inflate(layoutInflater) | |
setContentView(binding.root) | |
setStoriesData() | |
for (story in stories) { | |
val storyBinding: RowSingleSurferStoryBinding = | |
RowSingleSurferStoryBinding.inflate(layoutInflater) | |
Glide.with(this) | |
.load(story.storyUrl) | |
.into(storyBinding.civStory) | |
binding.llSurferStories.addView(storyBinding.root) | |
} | |
setSurferPostsData() | |
for (post in posts) { | |
val postBinding: RowSingleSurferPostBinding = | |
RowSingleSurferPostBinding.inflate(layoutInflater) | |
Glide.with(this) | |
.load(post.profilePicUrl) | |
.into(postBinding.civSurfer) | |
Glide.with(this) | |
.load(post.postUrl) | |
.into(postBinding.ivPostImage) | |
postBinding.tvPostBy.text = post.name | |
postBinding.tvPostedOn.text = post.postedOn | |
postBinding.tvPostTitle.text = post.title | |
postBinding.tvLocation.text = post.location | |
postBinding.tvLikeCount.text = "${post.likeCount} likes" | |
postBinding.ivPostImage.setOnClickListener { | |
val intent = Intent(this, SurfersThirdActivity::class.java) | |
Toast.makeText(this, postBinding.tvPostTitle.text, Toast.LENGTH_SHORT).show() | |
startActivity(intent) | |
} | |
binding.llSurferPosts.addView(postBinding.root) | |
} | |
} | |
private fun setStoriesData() { | |
stories.add(Story("https://i.pinimg.com/564x/51/7c/af/517caf0d930f526896eb811b3869c31c.jpg")) | |
stories.add(Story("https://i.pinimg.com/564x/44/3e/cb/443ecb7f724bc99256cec196a881cce1.jpg")) | |
stories.add(Story("https://i.pinimg.com/736x/1c/3b/41/1c3b41e00fb3efd6df810739af9e4b65.jpg")) | |
stories.add(Story("https://i.pinimg.com/564x/51/7c/af/517caf0d930f526896eb811b3869c31c.jpg")) | |
stories.add(Story("https://i.pinimg.com/564x/51/7c/af/517caf0d930f526896eb811b3869c31c.jpg")) | |
stories.add(Story("https://i.pinimg.com/564x/44/3e/cb/443ecb7f724bc99256cec196a881cce1.jpg")) | |
stories.add(Story("https://i.pinimg.com/736x/1c/3b/41/1c3b41e00fb3efd6df810739af9e4b65.jpg")) | |
stories.add(Story("https://i.pinimg.com/564x/51/7c/af/517caf0d930f526896eb811b3869c31c.jpg")) | |
} | |
private fun setSurferPostsData() { | |
posts.add( | |
SurferPost( | |
"https://i.pinimg.com/564x/51/7c/af/517caf0d930f526896eb811b3869c31c.jpg", | |
"https://i.pinimg.com/564x/44/3e/cb/443ecb7f724bc99256cec196a881cce1.jpg", | |
"Ikhlaq", | |
"2 hrs ago", | |
30, | |
"Today i surfed at Goa", | |
"Goa" | |
) | |
) | |
posts.add( | |
SurferPost( | |
"https://i.pinimg.com/564x/51/7c/af/517caf0d930f526896eb811b3869c31c.jpg", | |
"https://i.pinimg.com/736x/1c/3b/41/1c3b41e00fb3efd6df810739af9e4b65.jpg", | |
"Amaar", | |
"3 hrs ago", | |
20, | |
"Today i surfed at Karnatka", | |
"Karnatka" | |
) | |
) | |
posts.add( | |
SurferPost( | |
"https://i.pinimg.com/564x/51/7c/af/517caf0d930f526896eb811b3869c31c.jpg", | |
"https://i.pinimg.com/736x/1c/3b/41/1c3b41e00fb3efd6df810739af9e4b65.jpg", | |
"Zakir", | |
"1 hrs ago", | |
30, | |
"Today i surfed at London", | |
"London" | |
) | |
) | |
posts.add( | |
SurferPost( | |
"https://i.pinimg.com/564x/51/7c/af/517caf0d930f526896eb811b3869c31c.jpg", | |
"https://i.pinimg.com/564x/51/7c/af/517caf0d930f526896eb811b3869c31c.jpg", | |
"Ikhlaq", | |
"2 hrs ago", | |
30, | |
"Today i surfed at Goa", | |
"Goa" | |
) | |
) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment