【问题标题】:Technical Details of Android Lollipop Settings ViewAndroid Lollipop 设置视图的技术细节
【发布时间】:2015-06-01 20:56:01
【问题描述】:
我想知道您将如何为手机和平板电脑实现 Android 设置视图之类的功能?它看起来不像使用 CardView 的 ListView 或 RecyclerView?您会使用哪个 Android 类或组件来实现/设计外观相似的 ListView?
它在平板电脑上是两列布局,在手机上是一列布局:
任何示例代码或提示将不胜感激。
【问题讨论】:
标签:
android
android-listview
android-5.0-lollipop
android-cardview
android-recyclerview
【解决方案1】:
您可以将RecyclerView 和CardView 组合用于常规设置(例如:无线和网络或设备),然后您可以在每张卡内使用GridView 来保存特定设置(例如:WiFi 或控制器)。然后要完成两列技巧,请在 xml 文件中使用 resource qualifiers,其中包含要显示的列数的整数。
我会给你一个代码的概述。
您有一个像 recycler_layout.xml 这样的 xml 文件,其中包含所有内容的框架。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/friend_rv"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
然后你就有了一张卡片的框架,里面有一个 GridView。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/settings_card">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Your General Setting Title"
android:id="@+id/textView3" />
<GridView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="@+id/setting_content"
android:numColumns="@integer/yourColumnInteger"/>
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
最后,您有一个类似 myIntegers.xml 的文件,其中包含yourColumnInteger,如果用户在手机上(即他们的屏幕为 X 尺寸),您将值定义为 1,如果用户在平板电脑上(即他们的屏幕是Y尺寸,大于X)
那么你所要做的就是为这个东西连接所有的适配器。您需要一个填充卡片的适配器和一个填充特定设置的 GridView 适配器。 (并且我假设您了解您可能需要另一个 xml 布局来制作特定设置的框架,例如垂直线性布局中的设置图标和名称)