diff options
author | Deepanshu Gupta <deepanshu@google.com> | 2015-08-26 15:01:12 -0700 |
---|---|---|
committer | Trevor Johns <trevorjohns@google.com> | 2015-08-26 15:10:05 -0700 |
commit | 38b067e7e55384d180c49bca4f28570d8cc0a439 (patch) | |
tree | e59e1da60c28535b30fba1cb6664729bb34c2561 /system/AppUsageStatistics | |
parent | 57690c21113d5dff8b89b1fb76a5ac94bdbbefab (diff) | |
download | android-38b067e7e55384d180c49bca4f28570d8cc0a439.tar.gz |
Instantiate RecyclerView.LayoutManager in XML.
In newer versions of RecyclerView, layout manager can be instantiated
via an XML attribute. Use the feature as it results in better layout
previews in Android Studio. This also encourages developers to find more
XML attributes like spanCount in case of GridLayoutManager.
Change-Id: I9bac1058181722d861cbe8d285df7edc944fc4b2
[trevorjohns@google.com: Moved from //development, paths updated.]
Signed-off-by: Trevor Johns <trevorjohns@google.com>
Diffstat (limited to 'system/AppUsageStatistics')
2 files changed, 7 insertions, 5 deletions
diff --git a/system/AppUsageStatistics/Application/src/main/java/com/example/android/appusagestatistics/AppUsageStatisticsFragment.java b/system/AppUsageStatistics/Application/src/main/java/com/example/android/appusagestatistics/AppUsageStatisticsFragment.java index 9f54d02c..019bde9e 100644 --- a/system/AppUsageStatistics/Application/src/main/java/com/example/android/appusagestatistics/AppUsageStatisticsFragment.java +++ b/system/AppUsageStatistics/Application/src/main/java/com/example/android/appusagestatistics/AppUsageStatisticsFragment.java @@ -24,7 +24,6 @@ import android.graphics.drawable.Drawable; import android.os.Bundle; import android.provider.Settings; import android.support.v4.app.Fragment; -import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.util.Log; import android.view.LayoutInflater; @@ -91,10 +90,9 @@ public class AppUsageStatisticsFragment extends Fragment { public void onViewCreated(View rootView, Bundle savedInstanceState) { super.onViewCreated(rootView, savedInstanceState); - mLayoutManager = new LinearLayoutManager(getActivity()); mUsageListAdapter = new UsageListAdapter(); mRecyclerView = (RecyclerView) rootView.findViewById(R.id.recyclerview_app_usage); - mRecyclerView.setLayoutManager(mLayoutManager); + mLayoutManager = mRecyclerView.getLayoutManager(); mRecyclerView.scrollToPosition(0); mRecyclerView.setAdapter(mUsageListAdapter); mOpenUsageSettingButton = (Button) rootView.findViewById(R.id.button_open_usage_setting); diff --git a/system/AppUsageStatistics/Application/src/main/res/layout/fragment_app_usage_statistics.xml b/system/AppUsageStatistics/Application/src/main/res/layout/fragment_app_usage_statistics.xml index 1d567b76..297bf1e3 100644 --- a/system/AppUsageStatistics/Application/src/main/res/layout/fragment_app_usage_statistics.xml +++ b/system/AppUsageStatistics/Application/src/main/res/layout/fragment_app_usage_statistics.xml @@ -16,11 +16,13 @@ --> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:app="http://schemas.android.com/apk/res-auto" android:gravity="center_vertical" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" - android:padding="@dimen/margin_medium"> + android:padding="@dimen/margin_medium" + > <Button android:id="@+id/button_open_usage_setting" android:layout_width="wrap_content" @@ -50,6 +52,8 @@ android:scrollbars="vertical" android:drawSelectorOnTop="true" android:layout_width="match_parent" - android:layout_height="match_parent"/> + android:layout_height="match_parent" + app:layoutManager="LinearLayoutManager" + /> </LinearLayout> |