日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > Android >内容正文

Android

android include 点击事件,Android编程之include文件的使用方法

發布時間:2023/12/20 Android 21 豆豆
生活随笔 收集整理的這篇文章主要介紹了 android include 点击事件,Android编程之include文件的使用方法 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

本文實例分析了Android編程之include文件的使用方法。分享給大家供大家參考,具體如下:

記得很久以前,聽一位大神說,程序員都很懶,不懶惰的程序員不是好程序員,當時不明白什么意思.后來慢慢的懂得了它的意思,好的程序員不要做重復的工作.

我們在android的布局文件中,常會遇到一些相同的布局,每個頁面都寫,一是比較麻煩,二是一旦有修改還得改多個文件.這個時候我們就可以用到include了.

非常簡單的使用,下面看代碼

include的文件scollandlisttitle.xml

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:orientation="vertical"

>

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:orientation="horizontal"

android:background="#000000"

>

android:id="@+id/txt_left_f"

android:layout_width="0dp"

android:layout_height="50dp"

android:layout_weight="1"

android:gravity="center"

android:text="文字"

android:clickable="true"

/>

android:id="@+id/txt_right_f"

android:layout_width="0dp"

android:layout_height="50dp"

android:layout_weight="1"

android:gravity="center"

android:text="圖片"

android:clickable="true"

/>

android:id="@+id/view_line"

android:layout_width="50dp"

android:layout_height="1dp"

android:background="#FF0066"

/>

再看調用它的頁面:scollandlistviewpager.xml

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical"

android:id="@+id/vparent_layout">

android:id="@+id/vscrollView"

android:layout_width="match_parent"

android:layout_height="fill_parent"

android:fillViewport="true">

android:layout_width="match_parent"

android:layout_height="wrap_content">

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:orientation="vertical"

>

android:id="@+id/viamge"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:background="@drawable/pic"

android:scaleType="center"

/>

android:id="@+id/vtitle"

layout="@layout/scollandlisttitle"

/>

android:id="@+id/viewpager"

android:layout_width="match_parent"

android:layout_height="fill_parent"

/>

android:id="@+id/vtop_title"

layout="@layout/scollandlisttitle"

/>

上述include代碼部分就是兩個引用.加上之后,是不是就能看到include文件里的內容顯示出來了.

這里有一個問題,include里面的控件id是一樣的,這怎么辦呢.其實很簡單,它們是被不同的include所包含,所以在使用findViewById的時候,從包含它的include里面取就行了.下面是代碼

titleLayout = (LinearLayout)findViewById(R.id.vtitle);

toptitleLayout = (LinearLayout)findViewById(R.id.vtop_title);

//viewPager = (ViewPager)findViewById(R.id.viewpager);

//點擊按鈕事件

txt_left_fc = (TextView)toptitleLayout.findViewById(R.id.txt_left_f);

txt_left_fc.setOnClickListener(this);

txt_right_fc = (TextView)toptitleLayout.findViewById(R.id.txt_right_f);

txt_right_fc.setOnClickList

希望本文所述對大家Android程序設計有所幫助。

總結

以上是生活随笔為你收集整理的android include 点击事件,Android编程之include文件的使用方法的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。