• 动态更改屏幕方向LANDSCAPE与PORTRAIT 转


    动态更改屏幕方向……LANDSCAPE与PORTRAIT
    package irdc.ex05_22;
     
    import android.app.Activity;
    import android.content.pm.ActivityInfo;
    import android.os.Bundle;
    import android.view.Display;
    import android.view.View;
    import android.widget.Button;
    import android.widget.TextView;
    import android.widget.Toast;
     
    public class EX05_22 extends Activity
    {
    private TextView mTextView01;
    private Button mButton01;
     
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        mButton01 = (Button)findViewById(R.id.myButton1); 
        mTextView01 = (TextView)findViewById(R.id.myTextView1);
        
        if(getRequestedOrientation()==-1)
        {
          mTextView01.setText(getResources().getText
          (R.string.str_err_1001));
        }
        
        
        mButton01.setOnClickListener(new Button.OnClickListener()
        {
          @Override
          public void onClick(View arg0)
          {
            
            
            
            if(getRequestedOrientation()==-1)
            {
              
              mTextView01.setText(getResources().getText
              (R.string.str_err_1001));
            }
            else
            {
              if(getRequestedOrientation()==
                 ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE)
              {
                
                setRequestedOrientation
                (ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
              }
              else if(getRequestedOrientation()==
                      ActivityInfo.SCREEN_ORIENTATION_PORTRAIT)
              {
                
                setRequestedOrientation
                (ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
              }
            }
          }      
        });
    }
     
    @Override
    public void setRequestedOrientation(int requestedOrientation)
    {
        // TODO Auto-generated method stub
        
        
        switch(requestedOrientation)
        {
          
          case (ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE):
            mMakeTextToast
            (
              getResources().getText(R.string.str_msg1).toString(),
              false
            );
            break;
          
          case (ActivityInfo.SCREEN_ORIENTATION_PORTRAIT):
            mMakeTextToast
            (
              getResources().getText(R.string.str_msg2).toString(),
              false
            );
            break;
        }
        super.setRequestedOrientation(requestedOrientation);
    }
     
    @Override
    public int getRequestedOrientation()
    {
        // TODO Auto-generated method stub
        
        
        return super.getRequestedOrientation();
    }
     
    public void mMakeTextToast(String str, boolean isLong)
    {
        if(isLong==true)
        {
          Toast.makeText(EX05_22.this, str, Toast.LENGTH_LONG).show();
        }
        else
        {
          Toast.makeText(EX05_22.this, str, Toast.LENGTH_SHORT).show();
        }
    }
    }
     
    AndroidMinifest.xml
     
    <?xml version="1.0" encoding="utf-8"?>
    <manifest
    xmlns:android="http://schemas.android.com/apk/res/android"
    package="irdc.ex05_22"
    android:versionCode="1"
    android:versionName="1.0.0">
    <application
        android:icon="@drawable/icon"
        android:label="@string/app_name">
        <activity
          android:name=".EX05_22"
          android:label="@string/app_name"
          android:screenOrientation="portrait">
          <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
          </intent-filter>
        </activity>
    </application>
    </manifest>
  • 相关阅读:
    全站仪定向距离差 方向不差 这样敢放线吗
    关于老王
    cad巧用插件自定义填充图形
    老王教你永不会错的测量坐标方位角计算方法
    jqgrid 点击列头的超链接或按钮时,不触发列排序事件
    jqgrid 将列头设置为超链接或按钮
    jqgrid 设置隔行换色
    jqgrid 设置行编辑为本地端编辑状态
    jqgrid 让隐藏的列在编辑状态时出现且可编辑
    jqgrid 设置编辑行中的某列为下拉选择项
  • 原文地址:https://www.cnblogs.com/carbs/p/2586846.html
Copyright © 2020-2023  润新知