我想知道如何在手机和平板电脑上实现像Android设置视图这样的东西?它看起来不像一个使用CardView的ListView或RecyclerView?你会使用哪个Android类或组件来实现/设计一个外观相似的ListView?
它在平板电脑上是两栏布局,在手机上是一栏布局:
任何示例代码或技巧将不胜感激。
发布于 2015-06-12 23:21:59
您可以通过将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),则将该值定义为2。
然后你所要做的就是把所有的适配器连接起来。您需要一个用于填充卡的适配器和一个用于填充特定设置的GridView的适配器。(我假设您理解,框架可能需要另一个xml布局,该布局由垂直线性布局中的设置图标和名称等特定设置组成)
https://stackoverflow.com/questions/30583120
复制相似问题