Android Studio 开发笔记

LinearLayout 线性布局

常用LinearLayout标签

    android:id
    android:layout_width
    android:layout_height
    android:background
    android:layout_margin
    android:layout_padding
    android:orientation
    
    android:gravity的作用是 在父类的控件设置之后 子类的东西位置会基于gravity的设置

    View是所有的控件的父类

    layout_weight 平分权重占比的时候 把width设为0为标准分割 




    安卓开发基于布局和图片 和Java实现逻辑操作
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".MainActivity">
    
    <LinearLayout
        android:id = "@+id/ll_1"
        android:layout_width="200dp"
        android:layout_height="200dp"
        android:orientation="vertical"
        android:background="#000000"
        android:padding="50px"
        android:layout_marginBottom="20dp"
        >

        <View
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="#FF0033" />

    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:layout_marginTop="20dp"
        android:background="#0066FF"
        android:gravity="center_vertical"
        android:orientation="horizontal">

        <View
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:background="#FF0033"
            android:layout_weight="2"
            />

        <View
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:background="#000000"
            android:layout_weight="1"
            />

    </LinearLayout>

</LinearLayout>

 

RelativeLayout 相对布局

RelativeLayout
    最常用的属性
    android:layout_toLeftOf
    android:layout_toRightOf
    android:layout_alignBottom
    android:layout_alignParentBottom
    android:layout_below
    
    在父元素里面设置的padding 会在继承到子元素时变为外边距
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <View
        android:id="@+id/view_1"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:background="#000000"
        />

    <View
        android:id="@+id/view_2"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:background="#F6f6"
        android:layout_below="@id/view_1"
        />

    <LinearLayout
        android:id="@+id/ll_1"
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:layout_below="@id/view_2"
        android:background="#0066FF"
        android:padding="15dp">

        <View
            android:layout_width="100dp"
            android:layout_height="match_parent"
            android:background="#FF0033" />

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="#000000"
            android:padding="15dp">

            <View
                android:id="@+id/view_3"
                android:layout_width="100dp"
                android:layout_height="match_parent"
                android:background="#FF9900" />

            <View
                android:id="@+id/view_4"
                android:layout_width="100dp"
                android:layout_height="match_parent"
                android:layout_marginLeft="10dp"
                android:layout_toRightOf="@id/view_3"
                android:background="#FF9900" />

        </RelativeLayout>

    </LinearLayout>

</RelativeLayout>

 TextView

TextView
    中,下划线和去除需要在Java文件里面实现
    
    
package com.example.helloworld;

import androidx.appcompat.app.AppCompatActivity;

import android.graphics.Paint;
import android.os.Bundle;
import android.widget.TextView;

public class TextViewActivity extends AppCompatActivity {

    private TextView mTv4, mTv5, mTv6;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_text_view);
        mTv4 = (TextView)findViewById(R.id.tv_4);
        mTv4.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
        mTv4.getPaint().setAntiAlias(true);

        mTv5 = (TextView) findViewById(R.id.tv_5);
        mTv5.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG);

        mTv6 = findViewById(R.id.tv_6);
        mTv6.setText("Hey Mark sup");
    }
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:padding="20dp"
    >
    <TextView
        android:id="@+id/tv_1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="This is the text area"
        android:textColor="@color/black"
        android:textSize="30sp"
        />

    <TextView
        android:id="@+id/tv_2"
        android:layout_marginTop="10dp"
        android:layout_width="100dp"
        android:layout_height="wrap_content"
        android:maxLines="1"
        android:ellipsize="end"
        android:text="This is the text area"
        android:textColor="@color/black"
        android:textSize="30sp"
        />

    <TextView
        android:id="@+id/tv_3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Dog yao"
        android:textColor="@color/black"
        android:textSize="30sp"
        android:layout_marginTop="20dp"/>
<!--        android:drawableRight=""-->
        <!-- drawable 可以放入icon在文字行里面 跟文件路径      -->


    <!--    中划线和下划线-->
    <TextView
        android:id="@+id/tv_4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="This is the text area"
        android:textColor="@color/black"
        android:textSize="30sp"
        android:layout_marginTop="20dp"
        />

    <TextView
        android:id="@+id/tv_5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="This is the text area"
        android:textColor="@color/black"
        android:textSize="30sp"
        android:layout_marginTop="20dp"
        />

    <TextView
        android:id="@+id/tv_6"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="This is the text area"
        android:textColor="@color/black"
        android:textSize="30sp"
        android:layout_marginTop="20dp"
        />




</LinearLayout>

Button

EditText

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值