Android AS創(chuàng)建自定義布局案例詳解
先創(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),沒找到資源-->
<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)建類,要用的時(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)用庫-->
<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)文章希望大家以后多多支持腳本之家!
- Android notifyDataSetChanged() 動(dòng)態(tài)更新ListView案例詳解
- 解決java.lang.NoClassDefFoundError: android.support.v4.animation.AnimatorCompatHelper問題
- AndroidStudio報(bào)錯(cuò)Emulator:PANIC:Cannot find AVD system path. Please define ANDROID_SDK_ROOT(解決方案)
- Android實(shí)現(xiàn)快速滾動(dòng)FastScrollView效果
- 在Android項(xiàng)目中使用AspectJ的詳細(xì)攻詻
- 捕獲與解析Android NativeCrash
相關(guān)文章
Android左滑返回功能的實(shí)現(xiàn)示例代碼
本篇文章主要介紹了Android左滑返回的實(shí)現(xiàn)示例代碼,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-07-07
淺談Android性能優(yōu)化之內(nèi)存優(yōu)化
Android的內(nèi)存優(yōu)化是性能優(yōu)化中很重要的一部分,本文將詳細(xì)介紹Android性能優(yōu)化之內(nèi)存優(yōu)化。2021-06-06
Android實(shí)現(xiàn)滾動(dòng)刻度尺效果
本篇文章主要介紹了Android實(shí)現(xiàn)滾動(dòng)刻度尺效果,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-05-05
RXjava網(wǎng)絡(luò)獲取圖片數(shù)據(jù)的方法
這篇文章主要為大家詳細(xì)介紹了RXjava網(wǎng)絡(luò)獲取圖片數(shù)據(jù),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-08-08
Android中判斷網(wǎng)絡(luò)連接是否可用及監(jiān)控網(wǎng)絡(luò)狀態(tài)
獲取網(wǎng)絡(luò)信息需要在AndroidManifest.xml文件中加入相應(yīng)的權(quán)限,接下來詳細(xì)介紹Android中判斷網(wǎng)絡(luò)連接是否可用及監(jiān)控網(wǎng)絡(luò)狀態(tài),感興趣的朋友可以參考下2012-12-12
Android數(shù)據(jù)加密之Base64編碼算法的簡單實(shí)現(xiàn)
下面小編就為大家?guī)硪黄狝ndroid數(shù)據(jù)加密之Base64編碼算法的簡單實(shí)現(xiàn)。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2016-10-10
25個(gè)實(shí)用酷炫的Android開源UI框架
本文為大家分享了25個(gè)實(shí)用酷炫的Android開源UI框架,靈活運(yùn)用這些UI框架可在日常工作中節(jié)省不少時(shí)間2018-04-04
Android如何判斷當(dāng)前點(diǎn)擊位置是否在圓的內(nèi)部
這篇文章主要為大家詳細(xì)介紹了Android如何判斷當(dāng)前點(diǎn)擊位置是否在圓的內(nèi)部,解析拖動(dòng)圓形控件之內(nèi)響應(yīng)觸摸事件,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-05-05
Android項(xiàng)目實(shí)戰(zhàn)之仿網(wǎng)易新聞的頁面(RecyclerView )
這篇文章主要介紹了Android項(xiàng)目實(shí)戰(zhàn)之仿網(wǎng)易新聞的頁面,ViewPager作為RecyclerView的Header,感興趣的小伙伴們可以參考一下2016-01-01

