我想知道如何为手机和平板电脑实现Android设置视图?使用CardView看起来不像ListView或RecyclerView?您将使用哪个Android类或组件来实现/设计类似的ListView?
它是平板电脑上的2列布局和手机上的一列布局:
任何示例代码或提示都将不胜感激。
答案 0 :(得分: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,如果用户在平板电脑(即屏幕尺寸大于X的Y尺寸)
然后你所要做的就是连接所有适配器。您需要一个填充卡的适配器和一个填充特定设置的GridView适配器。 (我假设你明白你可能需要另一个xml布局,用于特定设置的框架,如垂直线性布局中的设置图标和名称)