日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

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

發布時間:2023/12/20 编程问答 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 android竖直和横向,如何在android中为纵向和横向模式定义不同的控件 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

定義,在這兩種資源的文件出現在你的代碼 并在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中为纵向和横向模式定义不同的控件的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。