• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
戈瑾
博客园    首页    新随笔    联系   管理    订阅  订阅
Android学习——day9

控制UI界面的方法

1.使用XML布局文件控制UI界面

(1)在Android应用的res/layout目录下编写XML布局文件

 

 (2)在Activity中使用以下java代码显示XML文件中布局的内容

setContentView(R.layout.hello_world_layout);

例如:

activity_main.xml文件

 1 <?xml version="1.0" encoding="utf-8"?>
 2 <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
 3     xmlns:tools="http://schemas.android.com/tools" android:id="@+id/activity_main"
 4     android:layout_width="match_parent" android:layout_height="match_parent"
 5     android:paddingBottom="@dimen/activity_vertical_margin"
 6     android:paddingLeft="@dimen/activity_horizontal_margin"
 7     android:paddingRight="@dimen/activity_horizontal_margin"
 8     android:paddingTop="@dimen/activity_vertical_margin"
 9     android:background="@mipmap/tq"
10     tools:context="com.example.MainActivity">
11 
12     <TextView android:layout_width="wrap_content"
13         android:layout_height="wrap_content"
14         android:layout_gravity="center"
15         android:textSize="30sp"
16         android:text="@string/start" />
17 
18 </FrameLayout>

 

 


 

 

2.在Java代码中控制UI界面

直接在MainActivity.java中编写


 

3.使用XML和java代码混合控制UI界面

4.开发自定义的View

 

posted on 2021-01-22 09:36  戈瑾  阅读(53)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3