Android的棒棒糖设置查看技术细节 [英] Technical Details of Android Lollipop Settings View

查看:355
本文介绍了Android的棒棒糖设置查看技术细节的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找出你将如何实现像一个Android设置查看同时适用于手机和平板电脑?它看起来并不像一个ListView或RecyclerView利用CardView?它的Andr​​oid类或部分将用于实现/设计一个外观类似的ListView?

I am trying to figure out how would you implement something like an Android Settings View for both phones and tablets? It doesn't look like a ListView or RecyclerView utilizing CardView? Which Android class or component would you use to implement/design a similar looking ListView?

及其分类在平板电脑上一个2列布局和一列布局的电话:

Its sort of a 2 column layout on tablets and one column layout on phones:

任何样品code或提示,将AP preciated。

Any sample code or tips would be appreciated.

推荐答案

您可以通过使用的 RecyclerView 和的 CardView ,在常规设置(例如:无线和网络或设备),那么你可以使用的 GridView的每一张卡内持有具体的设置(例如:WiFi或控制器)。然后,以完成两栏的技巧,使用<一个href=\"http://developer.android.com/guide/topics/resources/providing-resources.html#AlternativeResources\"相对=nofollow>资源预选赛上中包含要显示的列数的整数的XML文件。

You can accomplish this by using a combination of RecyclerView and CardView for the General settings (Ex: Wireless and networks or Device), then you can use a GridView inside each card to hold the specific settings (Ex: WiFi or Controller). Then to accomplish the two column trick, use resource qualifiers on an xml file containing an integer for the number of columns you want to display.

我给你的code的概述。

I'll give you an overview of the code.

您有一个像 recycler_layout.xml 的XML文件保存的一切框架。

You have an xml file like recycler_layout.xml that holds the frame for everything.

<?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卡帧。

Then you have the frame for a card with a GridView inside of it.

<?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 在其中定义值是1,如果用户是在手机上(即其屏幕为X的大小)和2,如果用户是在一个片剂(即他们的屏幕为Y尺寸,其是除了X大)

Finally you have a file like myIntegers.xml that contains yourColumnInteger where you define the value to be 1 if the user is on a phone (i.e. their screen is X size) and 2 if the user is on a tablet (i.e. their screen is Y size which is bigger than X)

然后,所有你需要做的就是线为东西所有适配器。你需要用于填充卡和用于填充特定设置GridView的适配器的适配器。 (我假设你明白,你可能会需要,使得像在垂直线性布局设置图标和名称的特定设置框另一个XML布局)

Then all you have to do is wire up all the adapters for the thing. You'll need an adapter that populates the cards and an adapter for the GridView that populates the specific settings. (And I assume you understand that you will probably need another xml layout for the frame that makes of the specific settings like the setting icon and name in a vertical linear layout)

这篇关于Android的棒棒糖设置查看技术细节的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆