创建卡片(Cards)

作者: Daz_ye | 来源:发表于2016-10-29 09:42 被阅读0次

*以下内容翻译自android wear的官方教程,本人水平有限,如有错误欢迎指出
home
以下正文


卡片为不同的app提供了统一的信息通知。本文将教你怎么给你的app创建卡片。

Wearable UI Library提供了手表上卡片通知的实现。她包含了 CardFrame
,这个类可以将控件(views)包裹在一个白色背景的卡片样式当中(圆润的边角和渐暗的阴影)。CardFrame只能包含一个子控件,通常是一个包含了其他各种控件的layout manager。
你有两种方法添加一个卡片:

  • 使用或继承CardFragment
  • 在你的layout当中添加 CardScrollView
    实例。

注意:本文将告诉你如何添加卡片,而在adroid wear上的通知也是以卡片的形式展示。 Adding Wearable Features to Notifications

创建一个卡片Fragment

CardFragment
提供了一个默认的标题,内容和一个小图标(icon)。

默认样式
添加CardFragment的方法:
  1. 在你的layout当中为包含这个card的元素指定一个id
  2. 在activity中创建CardFragment的实例
  3. 用fragment manager把这个实例加载到包裹她的容器(container)中

layout:

<android.support.wearable.view.BoxInsetLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="@drawable/robot_background"
android:layout_height="match_parent"
android:layout_width="match_parent">   
    <FrameLayout        
        android:id="@+id/frame_layout"     
        android:layout_width="match_parent"              
        android:layout_height="match_parent"   
        app:layout_box="bottom">  
    </FrameLayout>
</android.support.wearable.view.BoxInsetLayout>

activity:

protected void onCreate(Bundle savedInstanceState) {    
    super.onCreate(savedInstanceState);    
    setContentView(R.layout.activity_wear_activity2);   
    FragmentManager fragmentManager = getFragmentManager();    
    FragmentTransaction fragmentTransaction=fragmentManager.beginTransaction();    
    CardFragment cardFragment = CardFragment.create(getString(R.string.cftitle),  getString(R.string.cfdesc),R.drawable.p);    
    fragmentTransaction.add(R.id.frame_layout, cardFragment); 
    fragmentTransaction.commit();
}

自定义卡片样式可以继承CardFragment,然后重写(override) [onCreateContentView
](http://developer.android.youdaxue.com/reference/android/support/wearable/view/CardFragment.html#onCreateContentView(android.view.LayoutInflater, android.view.ViewGroup, android.os.Bundle)) 这个方法

在你的layout当中添加CardFrame

你也可以直接在你的layout当中添加卡片。当你想要自定义卡片样式的时候,可以使用这种方法。

在layout中添加CardFrame

图片效果的layout,你也可以创建更加复杂的布局:

<android.support.wearable.view.BoxInsetLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="@drawable/robot_background"
android:layout_height="match_parent"
android:layout_width="match_parent"> 
    <android.support.wearable.view.CardScrollView
        android:id="@+id/card_scroll_view"      
        android:layout_height="match_parent"     
        android:layout_width="match_parent"        
        app:layout_box="bottom">        
        <android.support.wearable.view.CardFrame  
             android:layout_height="wrap_content" 
             android:layout_width="fill_parent">    
             <LinearLayout               
                 android:layout_height="wrap_content"  
                 android:layout_width="match_parent"    
                 android:orientation="vertical"           
                 android:paddingLeft="5dp">           
                 <TextView 
                     android:fontFamily="sans-serif-light"
                     android:layout_height="wrap_content"       
                     android:layout_width="match_parent"           
                     android:text="@string/custom_card"                  
                     android:textColor="@color/black"                   
                     android:textSize="20sp"/>            
                  <TextView                 
                     android:fontFamily="sans-serif-light"   
                     android:layout_height="wrap_content"                            
                     android:layout_width="match_parent"               
                     android:text="@string/description"    
                     android:textColor="@color/black"   
                     android:textSize="14sp"/>     
           </LinearLayout>        
        </android.support.wearable.view.CardFrame>   
     </android.support.wearable.view.CardScrollView>
</android.support.wearable.view.BoxInsetLayout>

<CardScrollView>
元素探测屏幕的形状,并在不同的屏幕上显示不一样的卡片。在圆屏上使用更宽的margins。无论如何,在 <BoxInsetLayout>
中的 <CardScrollView>
被设置了layout_box="bottom"属性后,卡片就可以在底部对齐且内容不会被剪切。

相关文章

  • 创建卡片(Cards)

    *以下内容翻译自android wear的官方教程,本人水平有限,如有错误欢迎指出home以下正文 卡片为不同的a...

  • Material design - Components – C

    Cards - 卡片 A card is a sheet of material that serves as a...

  • CardView的使用

    Material Design中有一种很个性的设计概念:卡片式设计(Cards),Cards拥有自己独特的UI特征...

  • CardView的使用

    Material Design中有一种很个性的设计概念:卡片式设计(Cards),Cards拥有自己独特的UI特征...

  • 011 CardView的使用

    Material Design中有一种很个性的设计概念:卡片式设计(Cards),Cards拥有自己独特的UI特征...

  • Material Design —卡片(Cards)

    自上次参加完回音分享会后,我下定决心要洗心革面乖乖打基础,于是开启了这个part,争取两个月不间断更新,写完Mat...

  • ionic-CSS:Cards(卡片)

    Cards(卡片) 近年来卡片(card)的应用越来越流行,卡片提供了一个更好组织信息展示的工具。 像 Googl...

  • Android 使用CardView轻松实现卡片式设计

    Material design中有一种很个性的设计概念:卡片式设计(Cards),这种设计与传统的List Ite...

  • Android中CardView的使用

    一、简介 Material design中有一种很个性的设计概念:卡片式设计(Cards),这种设计与传统的Lis...

  • 赠送一张卡片,请查收

    Valentine Cards 情人节卡片 本人声明 2月14号在本人空间秀恩爱者 本人将截屏保存 如果以...

网友评论

    本文标题:创建卡片(Cards)

    本文链接:https://www.haomeiwen.com/subject/cdtyuttx.html