Android基础:Android概念

本文介绍了Android应用开发的基础概念,包括Activity、Fragment、布局文件的使用,重点讲解了View和ViewGroup的区别,以及如何通过findViewById操作控件。此外,还概述了常见控件的通用属性,如宽度、高度、布局和焦点设置等。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

基础概念

  1. Android的界面是承载在一个或者多个Activity上。
  2. Activity上可以显示fragment。
  3. 布局文件一般写在xml上。
  4. Android控件分为View和ViewGroup两种类型。
  5. 在Activity中,可以通过findViewById(R.id.控件id) 来获取指定id的控件对象进行操作。

第一个Android程序

        第一个Android程序

View 和 ViewGroup

在这里插入图片描述
        在Android视图中,View是在屏幕绘制用户能与之交互的一个对象,而ViewGroup则是一个用于存放View(和ViewGroup)对象的布局容器。
        类似ConstraintLayout,LinearLayout继承的就是ViewGroup,而TextView继承的是View.

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <TextView
        android:id="@+id/tv_one"
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:gravity="center"
        android:singleLine="true"
        android:ellipsize="marquee"
        android:marqueeRepeatLimit="marquee_forever"
        android:focusable="true"
        android:focusableInTouchMode="false"
        android:clickable="true"
        android:text="@string/tv_one"
        android:textColor="@color/purple_500"
        android:textSize="20dp"
        tools:ignore="MissingConstraints"
        tools:layout_editor_absoluteX="0dp">
        <requestFocus/>
    </TextView>

</androidx.constraintlayout.widget.ConstraintLayout>

Android控件通用属性

属性描述
layout_width
layout_height
padding内边距
margin外边距
visibilityvisible:显示;
invisible:不现实但是占用空间;
gone:不显示也不占用空间
focusable是否可以获取焦点
enabled是否启用该控件
background背景色,16进制值
id唯一标识符(id必须唯一),用于定位该控件
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值