changed column count to 5 for landscape

This commit is contained in:
danijoo
2015-10-29 21:20:42 +01:00
parent 80afe2944a
commit 0d16757cfd
7 changed files with 22 additions and 17 deletions

View File

@@ -1,6 +1,7 @@
package net.headlezz.udacityproject1;
import android.content.Context;
import android.content.res.Configuration;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.GridLayoutManager;
@@ -36,8 +37,8 @@ public class MovieListFragment extends Fragment {
/**
* The number of columns our movie grid shows
*/
private static final int NUM_COLUMNS = 3; // TODO adjust colum count for landscape
private static final int NUM_COLUMNS_PORTRAIT = 3;
private static final int NUM_COLUMNS_LAND = 5;
/**
* The currently selected sorting order of the list
* @see TMDBApi
@@ -68,7 +69,20 @@ public class MovieListFragment extends Fragment {
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
mMovieGridView.setLayoutManager(new GridLayoutManager(getActivity(), NUM_COLUMNS));
mMovieGridView.setLayoutManager(new GridLayoutManager(getActivity(), getNumColumns()));
}
/**
* @return the number of columns the app should show
* The result depends on screen orientation
*/
private int getNumColumns() {
int orientation = getActivity().getResources().getConfiguration().orientation;
if(orientation == Configuration.ORIENTATION_LANDSCAPE)
return NUM_COLUMNS_LAND;
else
return NUM_COLUMNS_PORTRAIT;
}
@Override

View File

@@ -20,7 +20,7 @@ import retrofit.http.Query;
public class TMDBApi {
private static final String BASE_URL = "http://api.themoviedb.org/3/";
private static final String IMAGE_BASE_URL = "http://image.tmdb.org/t/p/w185"; // TODO select size depending on device screen ratios
private static final String IMAGE_BASE_URL = "http://image.tmdb.org/t/p/w185";
/**
* These are the possible sorting orders

View File

@@ -10,7 +10,7 @@
<android.support.v7.widget.Toolbar android:id="@+id/toolbar"
android:layout_width="match_parent" android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary" app:popupTheme="@style/AppTheme.PopupOverlay" />
android:background="?attr/colorPrimary"/>
<FrameLayout
android:id="@+id/fragmentHolder"

View File

@@ -33,7 +33,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/movie_details_ivPoster"
android:layout_centerHorizontal="true" />
android:layout_alignParentEnd="true" />
<TextView
android:textAppearance="?android:attr/textAppearanceLarge"
@@ -42,7 +42,8 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/movie_details_tvReleaseDate"
android:layout_alignEnd="@+id/movie_details_tvReleaseDate" />
android:layout_alignStart="@+id/movie_details_tvReleaseDate"
android:layout_marginTop="39dp" />
<TextView
android:id="@+id/movie_details_tvOverview"

View File

@@ -1,7 +1,6 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent"
tools:showIn="@layout/activity_main"
tools:context=".MainActivityFragment">
<android.support.v7.widget.RecyclerView

View File

@@ -1,7 +0,0 @@
<resources>>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
</style>
</resources>

View File

@@ -11,7 +11,5 @@
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
</resources>