Challenge - 1: Restoring CrimeFragment's Margins

Since the book prompted that layout params non-existence in the case of ViewPagers, I used padding and this was fixed. Is this the only solution or are there alternatives :thinking:?

2 Likes

I think it really works good. I used the same solution.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="16dp"
    android:orientation="vertical"
    >
2 Likes

When i was creating fragment_crime.xml, i accidentally created Constraint Layout, so i just put Linear layout in and added:
android:layout_marginBottom=“16dp”
android:layout_marginEnd=“16dp”
android:layout_marginStart=“16dp”
android:layout_marginTop=“16dp”
app:layout_constraintBottom_toBottomOf=“parent”
app:layout_constraintEnd_toEndOf=“parent”
app:layout_constraintStart_toStartOf=“parent”
app:layout_constraintTop_toTopOf=“parent”

1 Like

I created one more linearlayout outside the current linearlayout.
So my solution is:
<LinearLayout xmlns:android=“http://schemas.android.com/apk/res/android”
android:layout_width=“match_parent”
android:layout_height=“match_parent”
android:orientation=“vertical”>

<LinearLayout
android:layout_width=“match_parent”
android:layout_height=“match_parent”
android:layout_margin=“16dp”
android:orientation=“vertical”>

----//----

</LinearLayout>

my solution:

    <dimen name="view_pager_margin">16dp</dimen>

mViewPager.setPageMargin(getResources().getDimensionPixelSize(R.dimen.view_pager_margin));