当前位置: 首页 > news >正文

国外比较好的资源网站哪个平台可以随便发广告

国外比较好的资源网站,哪个平台可以随便发广告,企业网站 数据库设计,别具光芒 Flash互动网站设计背景介绍: 在编写android小应用的时候,碰到了这样的一个问题:当推开手机的实体键盘时,屏幕由竖屏转换为横屏,此时应用程序的显示界面(Activity)就会被销毁了,这个让人比较郁闷。 如何才能让这个activity不被…

背景介绍:

在编写android小应用的时候,碰到了这样的一个问题:当推开手机的实体键盘时,屏幕由竖屏转换为横屏,此时应用程序的显示界面(Activity)就会被销毁了,这个让人比较郁闷。

如何才能让这个activity不被销毁呢?

------------------------------------- 背景分割线 ---------------------------------------------

资料查询:

在android开发网上有这么几段话:

If the configuration of the device (as defined by the Resources.Configuration class) changes, then anything displaying a user interface will need to update to match that configuration. Because Activity is the primary mechanism for interacting with the user, it includes special support for handling configuration changes.

Unless you specify otherwise, a configuration change (such as a change in screen orientation, language, input devices, etc) will cause your current activity to bedestroyed, going through the normal activity lifecycle process of onPause(),onStop(), andonDestroy() as appropriate. If the activity had been in the foreground or visible to the user, onceonDestroy() is called in that instance then a new instance of the activity will be created, with whatever savedInstanceState the previous instance had generated from onSaveInstanceState(Bundle).

In some special cases, you may want to bypass restarting of your activity based on one or more types of configuration changes. This is done with theandroid:configChanges attribute in its manifest. For any types of configuration changes you say that you handle there, you will receive a call to your current activity's onConfigurationChanged(Configuration) method instead of being restarted. If a configuration change involves any that you do not handle, however, the activity will still be restarted andonConfigurationChanged(Configuration) will not be called.

To declare that your Activity handles a configuration change, edit the appropriate<activity> element in your manifest file to include the android:configChanges attribute with a string value that represents the configuration that you want to handle. Possible values are listed in the documentation for theandroid:configChanges attribute (the most commonly used values areorientation to handle when the screen orientation changes and keyboardHidden to handle when the keyboard availability changes). You can declare multiple configuration values in the attribute by separating them with a pipe character ("|").

For example, the following manifest snippet declares an Activity that handles both the screen orientation change and keyboard availability change:

<activity android:name=".MyActivity"android:configChanges="orientation|keyboardHidden"android:label="@string/app_name">

Now when one of these configurations change, MyActivity is not restarted. Instead, the Activity receives a call toonConfigurationChanged(). This method is passed aConfiguration object that specifies the new device configuration. By reading fields in theConfiguration, you can determine the new configuration and make appropriate changes by updating the resources used in your interface. At the time this method is called, your Activity's Resources object is updated to return resources based on the new configuration, so you can easily reset elements of your UI without the system restarting your Activity.

------------------------------------ 分割线 -----------------------------------------

解决办法:

通过上面资料的阅读,解决办法就很简单了。

首先在Mainifest.xml的Activity元素中加入android:configChanges="orientation|keyboardHidden"属性

<activity android:name=".FileBrowser"
          android:label="@string/app_name"
          android:configChanges="orientation|keyboardHidden">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>

加入这条属性的含义是,应用程序将会处理屏幕方向和键盘状态(推出或合上)信息的改动。但对于其他的设备配置信息的改动则会由Android系统来处理(销毁当前Activity,然后重启一个新的Activity实例)。

那么,现在还需要在java代码的activity子类中加入配置信息改动的处理代码。这个也很简单

/**
 * onConfigurationChanged
 * the package:android.content.res.Configuration.
 * @param newConfig, The new device configuration.
 * 当设备配置信息有改动(比如屏幕方向的改变,实体键盘的推开或合上等)时,
 * 并且如果此时有activity正在运行,系统会调用这个函数。
 * 注意:onConfigurationChanged只会监测应用程序在AnroidMainifest.xml中通过
 * android:configChanges="xxxx"指定的配置类型的改动;
 * 而对于其他配置的更改,则系统会onDestroy()当前Activity,然后重启一个新的Activity实例。
 */
@Override
public void onConfigurationChanged(Configuration newConfig) {    
    super.onConfigurationChanged(newConfig);
    // 检测屏幕的方向:纵向或横向
    if (this.getResources().getConfiguration().orientation 
            == Configuration.ORIENTATION_LANDSCAPE) {
        //当前为横屏, 在此处添加额外的处理代码
    }
    else if (this.getResources().getConfiguration().orientation 
            == Configuration.ORIENTATION_PORTRAIT) {
        //当前为竖屏, 在此处添加额外的处理代码
    }
    //检测实体键盘的状态:推出或者合上    
    if (newConfig.hardKeyboardHidden 
            == Configuration.HARDKEYBOARDHIDDEN_NO){ 
        //实体键盘处于推出状态,在此处添加额外的处理代码
    } 
    else if (newConfig.hardKeyboardHidden
            == Configuration.HARDKEYBOARDHIDDEN_YES){ 
        //实体键盘处于合上状态,在此处添加额外的处理代码
    }
}
别忘了在java文件中加上 import android.content.res.Configuration

这样就OK了,屏幕方向改变时,应用程序的显示界面也会随着改动,而不是被销毁!

-----------------------------------还是分割线---------------------------------------------

扩展补充:

Activity中还有一属性和屏幕方向有关:

<activity 
   . . .
      android:screenOrientation=["unspecified" | "user" | "behind" |
                                 "landscape" | "portrait" |
                                 "sensor" | "nosensor"]
    . . .
&lt;/activity>

比如,在Mainifest.xml的Activity元素中增加这么一个属性:

android:screenOrientation="portrait"

则无论手机如何变动,拥有这个属性的activity都将是竖屏显示。

android:screenOrientation="landscape“为横屏显示。

这里提一个小知识,Anroid模拟器中,快捷键"ctrl+F11"可以实现转屏。


横竖屏切换后可采用不同的布局文件,方法如下:


默认情况下(竖屏)是调用res/layout 中的布局,如果要自定义横屏时的布局,可以在res/目录下新建一个layout-land 文件,在这个文件夹中放置横屏的布局,横竖屏的XML 文件的名字必须一样。=====

layout-port和layout-land

-----
在activity中做判断,代码如下:
Configuration newConfig = getResources().getConfiguration();" w/ j4 `: ]5 S0 ~) \/ D+ |
if(newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE){
//横屏时
setContentView(R.id.landscape);
}else if(newConfig.orientation == Configuration.ORIENTATION_PORTRAIT){
//竖屏时
setContentView(R.id.portrait);( o) y' l/ e3 \& \2 u
}6


转自http://www.cnblogs.com/hibraincol/archive/2010/09/18/1829862.html

转载于:https://www.cnblogs.com/moiyer/archive/2011/10/26/2316163.html

http://www.lbrq.cn/news/2467927.html

相关文章:

  • 建设银行积分兑换网站新媒体seo培训
  • 新疆新疆网页设计网站建设建网站流程
  • 免费h5源码资源源码站百度一下网页版
  • 网站维护与推广seo网络优化平台
  • 创建一个网站的一般步骤要点做个公司网站多少钱
  • 汉字域名的网站培训seo去哪家机构最好
  • 江门网站建设推广平台it培训学校it培训机构
  • 网站怎么做图片放映效果打开一个网站
  • 定制级高端网站建设湖南seo优化推荐
  • 网站建设年度汇报文职培训机构前十名
  • 易名中国域名门户网站营销软文的范文
  • 沈阳做网站推广的公司网址搜索ip地址
  • 礼叮当 一家做创意礼品定制的网站禁止搜索引擎收录的方法
  • 图库抚顺seo
  • 2018年深圳建设网站公司免费网站生成器
  • 在线定制平台烟台seo关键词排名
  • 政府网站建设实施的可行性分析天津seo数据监控
  • 个人网站备案地址百度指数的主要功能有
  • 汉口网站建设公司游戏优化是什么意思
  • 做网站便宜还是app便宜优化网站内容的方法
  • 1+手机官网首页seo网站优化网站编辑招聘
  • 网站日期插件廊坊快速优化排名
  • 为什么我有的网站打不开惠州seo关键词排名
  • phpstudy配置网站发帖推广平台
  • 自己做盈利视频网站网站推广上首页
  • 寿县城乡建设局网站百度舆情监测平台
  • 校园网站制作模板企业网络推广软件
  • 做暧暧小视频网站微信朋友圈广告投放
  • 电子商务网站建设过程报告推广团队在哪里找
  • 媒体查询做响应式网站网站权重排名
  • OCR工具集下载与保姆级安装教程!!
  • almalinux9.6-4070显卡-ollama-qwen2.5-7b
  • DNS 协议
  • LIMA:大语言模型对齐的“少即是多”革命——原理、实验与范式重构
  • 云原生 —— K8s 容器编排系统
  • 筑牢网站运营根基:售后工作的核心维度与实践方法