首页 文章 精选 留言 我的

精选列表

搜索[AI开发],共10000篇文章
优秀的个人博客,低调大师

Android UI开发第九篇——SlidingDrawer 抽屉效果

SlidingDrawer是自SDK 1.5才新加入的,实现Launcher的抽屉效果。SlidingDrawer配置上采用了水平展开或垂直展开两种(android:orientation)方式,在XML里必须指定其使用的android:handle与android:content,前者委托要展开的图片(Layout配置),后者则是要展开的Layout Content。 <?xmlversion="1.0"encoding="utf-8"?> <LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@drawable/i1" > <SlidingDrawer android:id="@+id/slidingdrawer" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" android:handle="@+id/handle" android:content="@+id/content"> <Button android:id="@+id/handle" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/ic_dialog_dialer" /> <LinearLayout android:id="@+id/content" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@drawable/default_bg"> <Button android:id="@+id/button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button" /> <EditText android:id="@+id/editText" android:layout_width="fill_parent" android:layout_height="wrap_content" /> </LinearLayout> </SlidingDrawer> </LinearLayout> 补充: 一、简介 SlidingDrawer隐藏屏外的内容,并允许用户通过handle以显示隐藏内容。它可以垂直或水平滑动,它有俩个View组成,其一是可以拖动的handle,其二是隐藏内容的View.它里面的控件必须设置布局,在布局文件中必须指定handle和content. 例如下面 <SlidingDrawer android:layout_width="fill_parent" android:layout_height="fill_parent" android:handle="@+id/handle" android:content="@+id/content" android:orientation="vertical" android:id="@+id/slidingdrawer"> <ImageButton android:id="@id/handle" android:layout_width="50dip" android:layout_height="44dip" android:src="@drawable/up" /> <LinearLayout android:id="@id/content" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#ffffff"> <TextView android:text="这是一个滑动式抽屉的示例" android:id="@+id/tv" android:textSize="18px" android:textColor="#000000" android:gravity="center_vertical|center_horizontal" android:layout_width="match_parent" android:textStyle="bold" android:layout_height="match_parent"></TextView> </LinearLayout> </SlidingDrawer> 二、重要属性 android:allowSingleTap:指示是否可以通过handle打开或关闭 android:animateOnClick:指示是否当使用者按下手柄打开/关闭时是否该有一个动画。 android:content:隐藏的内容 android:handle:handle(手柄) 三、重要方法 animateClose():关闭时实现动画。 close():即时关闭 getContent():获取内容 isMoving():指示SlidingDrawer是否在移动。 isOpened():指示SlidingDrawer是否已全部打开 lock():屏蔽触摸事件。 setOnDrawerCloseListener(SlidingDrawer.OnDrawerCloseListener onDrawerCloseListener):SlidingDrawer关闭时调用 unlock():解除屏蔽触摸事件。 toggle():切换打开和关闭的抽屉SlidingDrawer。 四、完整实例 1.布局文件slidingdrawer.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" android:background="@drawable/default_bg"> <SlidingDrawer android:layout_width="fill_parent" android:layout_height="fill_parent" android:handle="@+id/handle" android:content="@+id/content" android:orientation="vertical" android:id="@+id/slidingdrawer"> <ImageButton android:id="@id/handle" android:layout_width="50dip" android:layout_height="44dip" android:src="@drawable/up" /> <LinearLayout android:id="@id/content" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#ffffff"> <TextView android:text="这是一个滑动式抽屉的示例" android:id="@+id/tv" android:textSize="18px" android:textColor="#000000" android:gravity="center_vertical|center_horizontal" android:layout_width="match_parent" android:textStyle="bold" android:layout_height="match_parent"></TextView> </LinearLayout> </SlidingDrawer> </LinearLayout> 2.Java代码 package com.wjq; import android.app.Activity; import android.os.Bundle; import android.widget.ImageButton; import android.widget.SlidingDrawer; import android.widget.TextView; public class SlidingDrawerDemo extends Activity { private SlidingDrawer mDrawer; private ImageButton imbg; private Boolean flag=false; private TextView tv; /* (non-Javadoc) * @see android.app.Activity#onCreate(android.os.Bundle) */ @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.sildingdrawer); imbg=(ImageButton)findViewById(R.id.handle); mDrawer=(SlidingDrawer)findViewById(R.id.slidingdrawer); tv=(TextView)findViewById(R.id.tv); mDrawer.setOnDrawerOpenListener(new SlidingDrawer.OnDrawerOpenListener() { @Override public void onDrawerOpened() { flag=true; imbg.setImageResource(R.drawable.down); } }); mDrawer.setOnDrawerCloseListener(new SlidingDrawer.OnDrawerCloseListener(){ @Override public void onDrawerClosed() { flag=false; imbg.setImageResource(R.drawable.up); } }); mDrawer.setOnDrawerScrollListener(new SlidingDrawer.OnDrawerScrollListener(){ @Override public void onScrollEnded() { tv.setText("结束拖动"); } @Override public void onScrollStarted() { tv.setText("开始拖动"); } }); } } 本文转自xyz_lmn51CTO博客,原文链接:http://blog.51cto.com/xyzlmn/817346,如需转载请自行联系原作者

优秀的个人博客,低调大师

Android UI开发第十七篇——Android Fragment实例

TitlesFragment TitlesFragment继承自Fragment的子类ListFragment,使用了一个静态数组填充列表,重写了onListItemClick方法,showDetails方法展示ListView item的详情。 DetailsFragment df = DetailsFragment.newInstance(index);//获取详情Fragment的实例 FragmentTransaction ft = getFragmentManager().beginTransaction();//获取FragmentTransaction 实例 ft.replace(R.id.details, df); //使用DetailsFragment 的实例 ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE); ft.commit();//提交 这里就使用到了Android Fragment使用中介绍的第二种加载fragment的方法。看一下DetailsFragment : 布局文件中使用了fragment标签和FrameLayout标签。Android Fragment使用中介绍了2中嵌入Fragment的方法,这个实例中都用到,从布局文件看到有了fragment标签,这是一种使用方法,FrameLayout标签将会成为第二种加载fragment的载体view。 看一下程序实现(com.fragment.main.TitlesFragment): 效果图的左边是一个列表,右边是列表item的详情。 先看一下布局文件(layout): Fragment是Android honeycomb 3.0新增的概念,在Android——Fragment介绍、Android Fragment使用、Android FragmentManage FragmentTransaction介绍中做了关于Fragment的详细介绍。这一片主要通过一个实例了解Fragment的使用。 先看下实例效果图: 本文转自xyz_lmn51CTO博客,原文链接:http://blog.51cto.com/xyzlmn/817249,如需转载请自行联系原作者

优秀的个人博客,低调大师

Android UI开发第十三篇——android-viewflow

在论坛里,经常看到有人问如何实现UC或墨迹天气那样的拖动效果。其实大部分的实现都是参考了Launcher里的Workspace这个类。刚好看到有个开源项目也是实现了这种功能,地址在http://code.google.com/p/andro-views/,希望对有需要的人有所帮助,做出很cool的应用出来。 View Flow for Android ViewFlow is an Android UI widget providing a horizontally scrollableViewGroupwith items populated from anAdapter. Scroll down to the bottom of the page for a screen shot. The component is aLibrary Project. This means that there's no need to copy-paste resources into your own project, simply add the viewflow component as a reference to any project. Usage In your layout <org.taptwo.android.widget.ViewFlow android:id="@+id/viewflow" app:sidebuffer="5" /> The use ofapp:sidebufferis optional. It defines the number of Views to buffer on each side of the currently shown View. The default sidebuffer is 3, making up a grand total of 7 (3 * 2 + 1) Views loaded at a time (at max). To be able to use the more convenientapp:sidebufferattribute, the application namespace must be included in the same manner as the android namespace is. Please refer to the layout main.xml in the example project for a full example. Again, note that it's the application namespace andnotthe viewflow namespace that must be referred likexmlns:app="http://schemas.android.com/apk/res/your.application.package.here". In your activity ViewFlow viewFlow = (ViewFlow) findViewById(R.id.viewflow); viewFlow.setAdapter(myAdapter); Setting a different initial position (0 being default) is as easy as: viewFlow.setAdapter(myAdapter, 8); Although possible, you should not callsetSelection(...)immediately after callingsetAdapter(myAdapter)as that might load unnecessary views giving you a decrease in performance. Listen on screen change events If you need to listen to screen change events you would want to implement your ownViewFlow.ViewSwitchListenerand pass it to thesetOnViewSwitchListener()method. viewFlow.setOnViewSwitchListener(new ViewSwitchListener() { public void onSwitched(View v, int position) { // Your code here } }); Flow Indicator It is also possible to add a flow view indicator to your layout. The purpose of aFlowIndicatoris to present a visual representation of where in the item list focus is at. You may either implement aFlowIndicatoryourself or use an implementation provided by the View Flow library. The View Flow library currently supports the following indicators: Circle Flow Indicator This indicator shows a circle for eachViewin the adapter with a special circle representing the currently selected view (see screenshot below). <org.taptwo.android.widget.CircleFlowIndicator android:padding="10dip" android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/viewflowindic" android:background="#00000000"/> And then you'll need to connect yourViewFlowwith theFlowIndicator: CircleFlowIndicator indic = (CircleFlowIndicator) findViewById(R.id.viewflowindic); viewFlow.setFlowIndicator(indic); The following attributes are supported:activeColor,inactiveColor,activeType(either fill or stroke),inactiveType(either fill or stroke),fadeOut(time in ms until indicator fades out, 0 = never),radius. Title Flow Indicator This indicator presents the title of the previous, current and nextViewin the adapter (see screenshot below). <org.taptwo.android.widget.TitleFlowIndicator android:id="@+id/viewflowindic" android:layout_height="wrap_content" android:layout_width="fill_parent" app:footerLineHeight="2dp" app:footerTriangleHeight="10dp" app:textColor="#FFFFFFFF" app:selectedColor="#FFFFC445" app:footerColor="#FFFFC445" app:titlePadding="10dp" app:textSize="11dp" app:selectedSize="12dp" android:layout_marginTop="10dip" app:clipPadding="5dp" /> And then you'll need to connect yourViewFlowwith theFlowIndicator: TitleFlowIndicator indicator = (TitleFlowIndicator) findViewById(R.id.viewflowindic); indicator.setTitleProvider(myTitleProvider); viewFlow.setFlowIndicator(indicator); Building a jar file If you rather want a jar file instead of a including the project as an android library, runant jarin theandroid-viewflow/viewflowfolder, to build a jar file. Caveats The manifest states a min sdk version of 4, which is true. But in any case you want to support an api level < 8 you will have to forward anonConfigurationChangedevent to theViewFlowfrom yourActivity. I know this isn't a very nice solution, feel free to propose better ones! @Override public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); viewFlow.onConfigurationChanged(newConfig); } Contributions The following persons deserves a mention for their contributions: Eric Taix Marc Reichelt,http://marcreichelt.blogspot.com/ Want to contribute? GitHub has some great articles onhow to get started with Git and GitHuband how tofork a project. Contributers are recommended to fork the app on GitHub (but don't have too). Create a feature branch, push the branch to git hub, press Pull Request and write a simple explanation. One fix per commit. If let's say a commit closes the open issue 12. Just addcloses #12in your commit message to close that issue automagically. If you still feel uncomfortable contributing the project github-wise, don't hesistate to send a regular patch. All code that is contributed must be compliant withApache License 2.0. License Copyright (c) 2011Patrik Åkerfeldt Licensed under theApache License, Version 2.0 本文转自xyz_lmn51CTO博客,原文链接:http://blog.51cto.com/xyzlmn/817285,如需转载请自行联系原作者

资源下载

更多资源
Mario

Mario

马里奥是站在游戏界顶峰的超人气多面角色。马里奥靠吃蘑菇成长,特征是大鼻子、头戴帽子、身穿背带裤,还留着胡子。与他的双胞胎兄弟路易基一起,长年担任任天堂的招牌角色。

腾讯云软件源

腾讯云软件源

为解决软件依赖安装时官方源访问速度慢的问题,腾讯云为一些软件搭建了缓存服务。您可以通过使用腾讯云软件源站来提升依赖包的安装速度。为了方便用户自由搭建服务架构,目前腾讯云软件源站支持公网访问和内网访问。

Spring

Spring

Spring框架(Spring Framework)是由Rod Johnson于2002年提出的开源Java企业级应用框架,旨在通过使用JavaBean替代传统EJB实现方式降低企业级编程开发的复杂性。该框架基于简单性、可测试性和松耦合性设计理念,提供核心容器、应用上下文、数据访问集成等模块,支持整合Hibernate、Struts等第三方框架,其适用范围不仅限于服务器端开发,绝大多数Java应用均可从中受益。

Rocky Linux

Rocky Linux

Rocky Linux(中文名:洛基)是由Gregory Kurtzer于2020年12月发起的企业级Linux发行版,作为CentOS稳定版停止维护后与RHEL(Red Hat Enterprise Linux)完全兼容的开源替代方案,由社区拥有并管理,支持x86_64、aarch64等架构。其通过重新编译RHEL源代码提供长期稳定性,采用模块化包装和SELinux安全架构,默认包含GNOME桌面环境及XFS文件系统,支持十年生命周期更新。

用户登录
用户注册
修改密码
忘记密码