定义,在这两种资源的文件出现在你的代码 并在onCreate()在所有视图中Activity可以检查方向绑定的意见,你的类的对象。

示例。

在这里我们有包含在这两个文件的ImageView的,并在画像文件有一个TextView和景观它包含Button代替TextView

my_layout.xml在布局2个布局文件-land

android:id="@+id/button1"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Button" />

android:id="@+id/imageView1"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:src="@drawable/abs__ab_bottom_solid_dark_holo" />

my_layout.xml在布局端口文件夹

android:id="@+id/imageView1"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:src="@drawable/abs__ab_bottom_solid_dark_holo" />

android:id="@+id/textView1"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="TextView" />

这里是活动代码

package com.example.stackoverflow;

import android.app.Activity;

import android.content.res.Configuration;

import android.os.Bundle;

import android.view.Display;

import android.widget.Button;

import android.widget.ImageView;

import android.widget.TextView;

public class MyActivity extends Activity {

// landscape views

Button button1;

// protrati views

TextView textView1;

// common views (shared between landscape and protrait mode)

ImageView imageView1;

public MyActivity() {

// TODO Auto-generated constructor stub

}

@Override

protected void onCreate(Bundle savedInstanceState) {

// TODO Auto-generated method stub

super.onCreate(savedInstanceState);

setContentView(R.layout.my_layout);

imageView1 =(ImageView) findViewById(R.id.imageView1);//exist inside landscape file and portrait

if(getScreenOrientation() == Configuration.ORIENTATION_PORTRAIT){

textView1 = (TextView)findViewById(R.id.textView1);

}else{

button1 = (Button) findViewById(R.id.button1);

}

//when you want to access any thing that is not shared

//check the orientation

}

@Override

protected void onResume() {

super.onResume();

//let say that we want here to set a text on the textview and it's available only for protrait

if(getScreenOrientation() == Configuration.ORIENTATION_PORTRAIT){

//won't be null :) so we can set the text

textView1.setText("Hello Guys!");

}

}

// http://stackoverflow.com/a/6236110/671676

public int getScreenOrientation() {

Display getOrient = getWindowManager().getDefaultDisplay();

int orientation = Configuration.ORIENTATION_UNDEFINED;

if (getOrient.getWidth() == getOrient.getHeight()) {

orientation = Configuration.ORIENTATION_SQUARE;

} else {

if (getOrient.getWidth() < getOrient.getHeight()) {

orientation = Configuration.ORIENTATION_PORTRAIT;

} else {

orientation = Configuration.ORIENTATION_LANDSCAPE;

}

}

return orientation;

}

}

问什么,你不明白。

android竖直和横向,如何在android中为纵向和横向模式定义不同的控件相关推荐

  1. Android相对布局(RelativeLayout)常用属性、练习使用按键、文本框等控件、线性布局(LinearLayout)属性

    RelativeLayout中子控件常用属性: 子控件默认是从父控件的左上角开始排列的 相对于父控件 android:layout_alignParentTop="true" 和父 ...

  2. WPF 中使用附加属性,将任意 UI 元素或控件裁剪成圆形(椭圆)

    原文:WPF 中使用附加属性,将任意 UI 元素或控件裁剪成圆形(椭圆) 版权声明:本作品采用知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议进行许可.欢迎转载.使用.重新发布,但务必保 ...

  3. c++builder中dbgrid控件排序_如何实现APP中各种布局效果?学会这几个控件就够了...

    学习Flutter有一段时间了,也做了一些APP,但是总感觉对控件的使用一知半解,没有系统的概念,所以特意花了几天时间,把所有的控件都研究了一遍,总结出了常用的控件和使用方法, 俗话说:工欲善其事,必 ...

  4. matlab中axes显示,求助:在matlab的axes控件中显示图像

    利用plot命令重复刷新显示动画效果...本想在axes控件中显示,可是只有第一次plot命令在控件中显示,接下来的都是另开一个画图窗口显示图片..怎样让图片都在axes控件中显示呢?求高手指点. 附 ...

  5. 在 Visual Basic 6 中让用户在运行时移动和调整控件大小

      标题 在 Visual Basic 6 中让用户在运行时移动和调整控件大小 描述 此示例说明如何让用户在 Visual Basic 6 中在运行时移动控件和调整控件大小. 关键词 拖动.移动.调整 ...

  6. android led闪烁功能,如何在Android应用层中制作一个LED指示灯效果

    如何在Android应用层中制作一个LED指示灯效果 发布时间:2020-12-08 16:12:59 来源:亿速云 阅读:86 作者:Leah 本篇文章给大家分享的是有关如何在Android应用层中 ...

  7. android打电话的intent,如何在Android中使用intent打电话?

    如何在Android中使用intent打电话? 我正在使用以下代码在Android中进行调用,但它给了我安全例外,请帮忙. posted_by = "111-333-222-4"; ...

  8. android studio创建md,如何在Android Studio中设置*md文件打开方式

    最近在Android Studio中写一些Demo的时候,会顺便在里面创建一个.md文件用来进行Demo笔记的书写.然而Android Studio不带有markdown预览功能,所以我就琢磨如何在A ...

  9. Android清空Fragment缓存,如何在Android中清除Fragment Backstack

    如何在Android中清除Fragment Backstack 您好如何清除片段回堆栈正在使用以下逻辑,它不起作用... for(int i = 0; i < mFragmentManager. ...

最新文章

  1. org.gradle.api.internal.tasks.DefaultTaskInputs$TaskInput........
  2. 学习UI设计的一些小技巧你会了吗
  3. 创建和应用Java包文件的两种方式
  4. javascript:history.go()和history.back()的区别
  5. 西单大悦城苹果店4s_“神秘列车”复活!金融街-西单,3号免费专线今天回归...
  6. javascript 获取DropDownList选定值的方法
  7. 网络协议:HTTPS
  8. xdc如何设置输入延时
  9. opencv访问图像中每个像素的值
  10. CMMI认证需要什么条件?
  11. memcached可视化工具 treeNMS通用的安装方法(windows、mac、linux)
  12. html圈小猫小游戏
  13. git push reject 解决方案
  14. 俄罗斯方块Android版
  15. 知识图谱笔记(小象学院课程)
  16. Photoshop中的标尺、参考线
  17. 随笔记之lombok
  18. springboot+高校自习室座位管理小程序 毕业设计-附源码191028
  19. Qt调用7z实现压缩和解压缩
  20. 多线程的三种设计模式的介绍

热门文章

  1. 本杰明 富兰克林 道德13准则
  2. 骗子公司陆续公布中...
  3. 设计模式 之 创建者
  4. eclipse+tomcat开发web程序
  5. iOS CAGradientLayer颜色渐变
  6. Kotlin Native新增Objective-C互操作能力以及对WebAssembly的支持
  7. OCM_第十九天课程:Section9 —》Data Guard _ DATA GUARD 原理/DATA GUARD 应用/DATA GUARD 搭建...
  8. 2014-7-29-阿里电面-第一轮
  9. FB宣布将回购60亿美元股票 首席会计官将离职
  10. 数据库不完全恢复 以及恢复到测试环境: