欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android AS創(chuàng)建自定義布局案例詳解

 更新時間:2021年09月09日 14:57:52   作者:Gragon_ball  
這篇文章主要介紹了Android AS創(chuàng)建自定義布局案例詳解,本篇文章通過簡要的案例,講解了該項技術(shù)的了解與使用,以下就是詳細(xì)內(nèi)容,需要的朋友可以參考下

先創(chuàng)建一個title.xml

<LinearLayout
    xmlns:android="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:background="@drawable/ic_launcher_foreground"
    >
<!--background可以放圖片,放了合適的圖片比較好看,這里我比較隨意點,沒找到資源-->
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/title_Back"
        android:layout_margin="5dp"
        android:background="@drawable/ic_launcher_background"
        android:text="@string/Back"
        android:textColor="#fff"/>
    
    <TextView
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:id="@+id/title_Text"
        android:layout_weight="1"
        android:gravity="center"
        android:text="This is a title"
        android:textColor="#F44336"
        android:textSize="24sp"
        tools:ignore="HardcodedText"/>

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/title_edit"
        android:layout_margin="5dp"
        android:background="@drawable/ic_launcher_background"
        android:text="EDIT"
        android:textColor="#fff"
        tools:ignore="HardcodedText" />

這里是為了自定義布局,這就像C++中創(chuàng)建類,要用的時候直接調(diào)用就行了。
下面展示如何調(diào)用

activity_main.xml:

<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">
	<!--酷似C++調(diào)用庫-->
    <include layout="@layout/title"/>


</LinearLayout>

最后記得將標(biāo)題行隱藏起來,這樣才能模擬iphone的標(biāo)題欄

import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;


public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ActionBar actionBar=getSupportActionBar();
        if(actionBar!=null)
            actionBar.hide();//將標(biāo)題欄隱藏起來


    }
}

結(jié)果:

這是效果圖

到此這篇關(guān)于Android AS創(chuàng)建自定義布局案例詳解的文章就介紹到這了,更多相關(guān)Android AS創(chuàng)建自定義布局內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評論