Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
U
uv-amse-android
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Lucas NAURY
uv-amse-android
Commits
7a6069e4
Commit
7a6069e4
authored
Feb 17, 2024
by
Inès EL HADRI
💤
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add layout for grid
parent
b3ae2038
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
93 additions
and
45 deletions
+93
-45
HomeAdapter.java
...ain/java/com/example/tpleboncoin/ui/home/HomeAdapter.java
+12
-3
HomeFragment.java
...in/java/com/example/tpleboncoin/ui/home/HomeFragment.java
+7
-1
annonces_grid.xml
app/src/main/res/layout/annonces_grid.xml
+47
-0
annonces_liste.xml
app/src/main/res/layout/annonces_liste.xml
+27
-41
No files found.
app/src/main/java/com/example/tpleboncoin/ui/home/HomeAdapter.java
View file @
7a6069e4
...
...
@@ -16,6 +16,7 @@ public class HomeAdapter extends RecyclerView.Adapter<HomeAdapter.ViewHolder> {
private
static
final
String
TAG
=
"CustomAdapter"
;
private
Annonce
[]
mDataSet
;
private
boolean
mIsGrid
;
// BEGIN_INCLUDE(recyclerViewSampleViewHolder)
/**
...
...
@@ -52,8 +53,9 @@ public class HomeAdapter extends RecyclerView.Adapter<HomeAdapter.ViewHolder> {
*
* @param dataSet String[] containing the data to populate views to be used by RecyclerView.
*/
public
HomeAdapter
(
Annonce
[]
dataSet
)
{
public
HomeAdapter
(
Annonce
[]
dataSet
,
boolean
isGrid
)
{
mDataSet
=
dataSet
;
mIsGrid
=
isGrid
;
}
// BEGIN_INCLUDE(recyclerViewOnCreateViewHolder)
...
...
@@ -61,8 +63,15 @@ public class HomeAdapter extends RecyclerView.Adapter<HomeAdapter.ViewHolder> {
@Override
public
ViewHolder
onCreateViewHolder
(
ViewGroup
viewGroup
,
int
viewType
)
{
// Create a new view.
View
v
=
LayoutInflater
.
from
(
viewGroup
.
getContext
())
.
inflate
(
R
.
layout
.
annonces_liste
,
viewGroup
,
false
);
View
v
;
if
(
mIsGrid
)
{
v
=
LayoutInflater
.
from
(
viewGroup
.
getContext
())
.
inflate
(
R
.
layout
.
annonces_grid
,
viewGroup
,
false
);
}
else
{
v
=
LayoutInflater
.
from
(
viewGroup
.
getContext
())
.
inflate
(
R
.
layout
.
annonces_liste
,
viewGroup
,
false
);
}
return
new
ViewHolder
(
v
);
}
...
...
app/src/main/java/com/example/tpleboncoin/ui/home/HomeFragment.java
View file @
7a6069e4
...
...
@@ -69,7 +69,7 @@ public class HomeFragment extends Fragment {
}
setRecyclerViewLayoutManager
(
mCurrentLayoutManagerType
);
mAdapter
=
new
HomeAdapter
(
mDataset
);
mAdapter
=
new
HomeAdapter
(
mDataset
,
false
);
// Set CustomAdapter as the adapter for RecyclerView.
mRecyclerView
.
setAdapter
(
mAdapter
);
// END_INCLUDE(initializeRecyclerView)
...
...
@@ -111,10 +111,16 @@ public class HomeFragment extends Fragment {
case
GRID_LAYOUT_MANAGER:
mLayoutManager
=
new
GridLayoutManager
(
getActivity
(),
SPAN_COUNT
);
mCurrentLayoutManagerType
=
LayoutManagerType
.
GRID_LAYOUT_MANAGER
;
mAdapter
=
new
HomeAdapter
(
mDataset
,
true
);
// Set CustomAdapter as the adapter for RecyclerView.
mRecyclerView
.
setAdapter
(
mAdapter
);
break
;
case
LINEAR_LAYOUT_MANAGER:
mLayoutManager
=
new
LinearLayoutManager
(
getActivity
());
mCurrentLayoutManagerType
=
LayoutManagerType
.
LINEAR_LAYOUT_MANAGER
;
mAdapter
=
new
HomeAdapter
(
mDataset
,
false
);
// Set CustomAdapter as the adapter for RecyclerView.
mRecyclerView
.
setAdapter
(
mAdapter
);
break
;
default
:
mLayoutManager
=
new
LinearLayoutManager
(
getActivity
());
...
...
app/src/main/res/layout/annonces_grid.xml
0 → 100644
View file @
7a6069e4
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android=
"http://schemas.android.com/apk/res/android"
xmlns:app=
"http://schemas.android.com/apk/res-auto"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:gravity=
"center_vertical"
android:minHeight=
"50dp"
>
<RelativeLayout
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:padding=
"10dp"
>
<TextView
android:id=
"@+id/adresse_annonce"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_below=
"@id/prix_annonce"
android:text=
"Adresse, 59000 Douai"
/>
<ImageView
android:id=
"@+id/imageView"
android:layout_width=
"80dp"
android:layout_height=
"80dp"
android:src=
"@drawable/ic_launcher_background"
/>
<TextView
android:id=
"@+id/titre_annonce"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_below=
"@+id/imageView"
android:fontFamily=
"sans-serif-medium"
android:text=
"Titre annonce de test"
android:textAppearance=
"@style/TextAppearance.AppCompat.Medium"
/>
<TextView
android:id=
"@+id/prix_annonce"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_below=
"@id/titre_annonce"
android:layout_weight=
"1"
android:fontFamily=
"sans-serif-black"
android:text=
"12.99€"
android:textAppearance=
"@style/TextAppearance.AppCompat.Medium"
/>
</RelativeLayout>
</FrameLayout>
app/src/main/res/layout/annonces_liste.xml
View file @
7a6069e4
...
...
@@ -5,60 +5,46 @@
android:gravity=
"center_vertical"
android:minHeight=
"50dp"
>
<
Linear
Layout
<
Relative
Layout
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:layout_marginBottom=
"8dp"
android:baselineAligned=
"false"
android:gravity=
"center_vertical"
android:orientation=
"horizontal"
android:padding=
"8dp"
>
android:layout_height=
"match_parent"
android:padding=
"10dp"
>
<LinearLayout
<ImageView
android:id=
"@+id/imageView"
android:layout_width=
"80dp"
android:layout_height=
"80dp"
android:src=
"@drawable/ic_launcher_background"
/>
<TextView
android:id=
"@+id/titre_annonce"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:orientation=
"horizontal"
>
<ImageView
android:id=
"@+id/imageView"
android:layout_width=
"40dp"
android:layout_height=
"40dp"
android:src=
"@drawable/ic_launcher_background"
/>
<LinearLayout
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:orientation=
"vertical"
>
<TextView
android:id=
"@+id/titre_annonce"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:fontFamily=
"sans-serif-medium"
android:paddingLeft=
"8dp"
android:text=
"Titre annonce de test"
android:textAppearance=
"@style/TextAppearance.AppCompat.Medium"
/>
<TextView
android:id=
"@+id/adresse_annonce"
android:layout_width=
"148dp"
android:layout_height=
"wrap_content"
android:paddingLeft=
"8dp"
android:text=
"Adresse, 59000 Douai"
/>
</LinearLayout>
android:fontFamily=
"sans-serif-medium"
android:text=
"Titre annonce de test"
android:layout_below=
"@+id/imageView"
android:textAppearance=
"@style/TextAppearance.AppCompat.Medium"
/>
</LinearLayout>
<TextView
android:id=
"@+id/adresse_annonce"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:text=
"Adresse, 59000 Douai"
android:layout_toEndOf=
"@id/titre_annonce"
android:layout_alignTop=
"@id/titre_annonce"
android:textAlignment=
"viewEnd"
/>
<TextView
android:id=
"@+id/prix_annonce"
android:layout_width=
"
wrap_cont
ent"
android:layout_width=
"
match_par
ent"
android:layout_height=
"wrap_content"
android:layout_weight=
"1"
android:fontFamily=
"sans-serif-black"
android:text=
"12.99€"
android:textAlignment=
"viewEnd"
android:layout_toRightOf=
"@id/imageView"
android:textAppearance=
"@style/TextAppearance.AppCompat.Medium"
/>
</LinearLayout>
</RelativeLayout>
</FrameLayout>
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment