Header ads

Header ads
» » Xoay màn hình

Ví dụ xoay màn hình trong Android

screenOrientation  là thuộc tính của phần tử activity. Hướng màn hình của một activity có thể là: dọc(portrait), landscape, sensor, không xác định .v.v, . Cần phải khai báo nó trong tập tin. ví dụ:

  <activity  android:name="com.example.screenorientation.MainActivity"                android:label="@string/app_name"                 android:screenOrientation="landscape" />  

Các giá trị chung cho thuộc tính screenOrientation như sau:

Giá trị Mô tả
unspecified Giá trị mặc định. không xác định
portrait Theo chiều dọc
landscape Theo chiều ngang
sensor orientation sẽ dò hướng bằng cách dựa vào sensor

Ví dụ chế độ màn hình theo hướng landscape trong Android

File: activity_main.xml

  <RelativeLayout xmlns:androclass="http://schemas.android.com/apk/res/android"        xmlns:tools="http://schemas.android.com/tools"        android:layout_width="match_parent"        android:layout_height="match_parent"        android:paddingBottom="@dimen/activity_vertical_margin"        android:paddingLeft="@dimen/activity_horizontal_margin"        android:paddingRight="@dimen/activity_horizontal_margin"        android:paddingTop="@dimen/activity_vertical_margin"        tools:context=".MainActivity" >            <Button            android:id="@+id/button1"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:layout_marginLeft="66dp"            android:layout_marginTop="73dp"            android:text="Button"            android:onClick="onClick"             />            <EditText            android:id="@+id/editText1"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:layout_centerHorizontal="true"            android:ems="10" />        </RelativeLayout>  

Activity class

File: MainActivity.java

  package com.example.f;        import android.os.Bundle;    import android.app.Activity;    import android.view.Menu;    import android.view.View;    import android.view.View.OnClickListener;    import android.widget.Button;    import android.widget.EditText;        public class MainActivity extends Activity{        EditText editText1;        Button button1;        @Override        protected void onCreate(Bundle savedInstanceState) {            super.onCreate(savedInstanceState);            setContentView(R.layout.activity_main);                        editText1=(EditText)findViewById(R.id.editText1);            button1=(Button)findViewById(R.id.button1);        }        public void onClick(View v) {            editText1.setText("O android");        }    }  

AndroidManifest.xml

File: AndroidManifest.xml


Download ví dụ


Kết quả:

 



Cập nhật công nghệ từ Youtube tại link: https://www.youtube.com/channel/UCOxeYcvZPGf-mGLYSl_1LuA/videos
Để tham gia khóa học công nghệ truy cập link: http://thuvien.hocviendaotao.com
Mọi hỗ trợ về công nghệ email: dinhanhtuan68@gmail.com

About Học viện đào tạo trực tuyến

Xinh chào bạn. Tôi là Đinh Anh Tuấn - Thạc sĩ CNTT. Email: dinhanhtuan68@gmail.com .
- Nhận đào tạo trực tuyến lập trình dành cho nhà quản lý, kế toán bằng Foxpro, Access 2010, Excel, Macro Excel, Macro Word, chứng chỉ MOS cao cấp, IC3, tiếng anh, phần mềm, phần cứng .
- Nhận thiết kế phần mềm quản lý, Web, Web ứng dụng, quản lý, bán hàng,... Nhận Thiết kế bài giảng điện tử, số hóa tài liệu...
HỌC VIỆN ĐÀO TẠO TRỰC TUYẾN:TẬN TÂM-CHẤT LƯỢNG.
«
Next
Bài đăng Mới hơn
»
Previous
Bài đăng Cũ hơn