首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Android棒棒糖设置视图技术细节

Android棒棒糖设置视图技术细节
EN

Stack Overflow用户
提问于 2015-06-02 04:56:01
回答 1查看 669关注 0票数 0

我想知道如何在手机和平板电脑上实现像Android设置视图这样的东西?它看起来不像一个使用CardView的ListView或RecyclerView?你会使用哪个Android类或组件来实现/设计一个外观相似的ListView?

它在平板电脑上是两栏布局,在手机上是一栏布局:

任何示例代码或技巧将不胜感激。

EN

回答 1

Stack Overflow用户

发布于 2015-06-12 23:21:59

您可以通过将RecyclerViewCardView的组合用于常规设置(例如:无线和网络或设备)来完成此操作,然后可以在每个卡中使用GridView来保存特定设置(例如: WiFi或控制器)。然后,要完成两列技巧,可以对包含要显示的列数的整数的xml文件使用resource qualifiers

我将给你一个代码的概述。

您有一个像recycler_layout.xml这样的xml文件,它包含了所有内容的框架。

代码语言:javascript
运行
复制
<?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。

代码语言:javascript
运行
复制
<?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布局,该布局由垂直线性布局中的设置图标和名称等特定设置组成)

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30583120

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档