最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

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

先創(chuàng)建一個(gè)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可以放圖片,放了合適的圖片比較好看,這里我比較隨意點(diǎn),沒(méi)找到資源-->
    <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)建類(lèi),要用的時(shí)候直接調(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)用庫(kù)-->
    <include layout="@layout/title"/>


</LinearLayout>

最后記得將標(biāo)題行隱藏起來(lái),這樣才能模擬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)題欄隱藏起來(lái)


    }
}

結(jié)果:

這是效果圖

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

相關(guān)文章

最新評(píng)論

三门峡市| 青冈县| 西青区| 北海市| 绍兴市| 两当县| 上蔡县| 武宣县| 胶南市| 界首市| 吴江市| 莱西市| 繁昌县| 汉川市| 东至县| 江西省| 石台县| 辛集市| 永昌县| 扎囊县| 普格县| 叙永县| 孟津县| 寿宁县| 河东区| 揭西县| 黑河市| 黔西县| 嘉鱼县| 石狮市| 姚安县| 顺昌县| 昭觉县| 泰顺县| 云浮市| 台中县| 大余县| 奉节县| 南皮县| 招远市| 潮州市|