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

歡迎訪問 生活随笔!

生活随笔

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

Android

构建用户界面 Android 应用中一些常用的小部件

發布時間:2025/5/22 Android 48 豆豆
生活随笔 收集整理的這篇文章主要介紹了 构建用户界面 Android 应用中一些常用的小部件 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

1. TextView 顯示文本信息

<TextViewandroid:id="@+id/textOne"android:layout_width="200dp"android:layout_height="200dp"android:gravity="center"android:text="TextView(顯示框)"android:textColor="#EA5246"android:textStyle="bold|italic"android:background="#000000"android:textSize="18sp" /> id:為TextView設置一個組件id,根據id,我們可以在Java代碼中通過findViewById()的方法獲取到該對象,然后進行相關屬性的設置,又或者使用RelativeLayout時,參考組件用的也是id! layout_width:組件的寬度,一般寫:**wrap_content**或者**match_parent(fill_parent)**,前者是控件顯示的內容多大,控件就多大,而后者會填滿該控件所在的父容器;當然也可以設置成特定的大小,比如我這里為了顯示效果,設置成了200dp。 layout_height:組件的高度,內容同上。 gravity:設置控件中內容的對齊方向,TextView中是文字,ImageView中是圖片等等。 text:設置顯示的文本內容,一般我們是把字符串寫到string.xml文件中,然后通過@String/xxx取得對應的字符串內容的,這里為了方便我直接就寫到""里,不建議這樣寫!!! textColor:設置字體顏色,同上,通過colors.xml資源來引用,別直接這樣寫! textStyle:設置字體風格,三個可選值:**normal**(無效果),**bold**(加粗),**italic**(斜體) textSize:字體大小,單位一般是用sp! background:控件的背景顏色,可以理解為填充整個控件的顏色,可以是圖片哦!

2. EditText 文本編輯

<EditText android:id="@+id/editOne"android:layout_width="match_parent" android:layout_height="wrap_content" android:text="TypeHere"android:textColor="#EA5246"android:textStyle="bold|italic"android:textSize="18sp" android:hint="Type"android:gravity="center" > <requestFocus /> </EditText> android:hint="默認提示文本" android:textColorHint="#95A1AA" <requestFocus /> //獲取焦點 android:minLines="3" //設置最小行的行數 android:maxLines="3" //設置最大行的行數android:singleLine="true" //實現單行輸入不換行android:textScaleX="1.5" //設置字與字的水平間隔 android:textScaleY="1.5" //設置字與字的垂直間隔android:paddingTop = "5dp" //組件內文字和組件邊框的距離

3. Button 普通按鈕

<Buttonandroid:id="@+id/btnOne"android:layout_width="match_parent"android:layout_height="wrap_content"android:background="@drawable/ic_launcher"android:text="按鈕"/>

4. ImageButton 圖片按鈕

<ImageButtonandroid:id="@+id/imageButton"android:layout_width="wrap_content"android:layout_height="wrap_content"android:src="@drawable/ic_launcher"/>

5. ToggleButton 開關按鈕

<ToggleButtonandroid:id="@+id/toggleButton"android:layout_width="match_parent"android:layout_height="wrap_content"android:checked="true" //將按鈕設置為ON狀態android:textOff="關閉聲音"android:textOn="打開聲音" />

6. RadioButton 單旋鈕,選中之后不能取消

<RadioButtonandroid:id="@+id/btnMan"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="男"android:checked="true"/>

7. RadioGroup 單選按鈕組

<RadioGroupandroid:id="@+id/radioGroup"android:layout_width="wrap_content"android:layout_height="wrap_content"android:orientation="horizontal"><RadioButtonandroid:id="@+id/btnMan"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="男"android:checked="true"/><RadioButtonandroid:id="@+id/btnWoman"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="女"/> </RadioGroup>

8. CheckBox 復選框,選中后可以取消

<CheckBoxandroid:id="@+id/checkBox0"android:layout_width="match_parent"android:layout_height="wrap_content"android:checked="true"android:text="唱歌" />

9. Spinner 下拉列表

<Spinnerandroid:id="@+id/spin_one"android:layout_width="match_parent"android:layout_height="wrap_content"android:entries="@array/data"android:prompt="@string/spin_title"android:spinnerMode="dropdown" /> //在res/values下編寫一個:myarrays.xml的文件 <string-array name="data"><item>帥哥</item><item>美女</item><item>大神</item> </string-array>

10. ListView 顯示列表,可以垂直滾動

<ListViewandroid:id="@+id/list_view"android:layout_width="match_parent"android:layout_height="match_parent"android:entries="@array/data" > </ListView>

11. ImageView 顯示圖像

<ImageViewandroid:id="@+id/imageView1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:background="@drawable/ic_launcher" /><ImageViewandroid:id="@+id/imageView2"android:layout_width="wrap_content"android:layout_height="wrap_content"android:background="@drawable/map" />

12. ScrollView 垂直滾動布局

<ScrollViewandroid:layout_width="match_parent"android:layout_height="match_parent"android:scrollbars="horizontal" ><LinearLayoutandroid:layout_width="500sp"android:layout_height="match_parent"android:orientation="vertical" ><ImageViewandroid:layout_width="500sp"android:layout_height="wrap_content"android:src="@drawable/map" /><ImageViewandroid:layout_width="500sp"android:layout_height="wrap_content"android:src="@drawable/map" /><ImageViewandroid:layout_width="500sp"android:layout_height="wrap_content"android:src="@drawable/map" /><ImageViewandroid:layout_width="500sp"android:layout_height="wrap_content"android:src="@drawable/map" /></LinearLayout> </ScrollView>

13. WebView 顯示網頁

//添加網絡權限 <uses-permission android:name="android.permission.INTERNET" /><WebViewandroid:id="@+id/webview"android:layout_width="match_parent"android:layout_height="match_parent" />//在activity public class MainActivity extends Activity {WebView webView;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);webView = (WebView) findViewById(R.id.webview);//加載網頁鏈接webView.loadUrl("https://www.baidu.com");} }

二、視圖組

1. 線性布局

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="fill_parent"android:layout_height="fill_parent"android:orientation="horizontal" ><TextViewandroid:id="@+id/textOne"android:layout_width="wrap_content"android:layout_height="fill_parent"android:layout_weight="0"android:background="#000000"android:text="Text1"android:textColor="#EA5246"android:textSize="18sp"android:textStyle="bold|italic" /><TextViewandroid:id="@+id/textTwo"android:layout_width="wrap_content"android:layout_height="fill_parent"android:layout_weight="1"android:background="#00aa00"android:text="Text2"android:textColor="#EA5246"android:textSize="18sp"android:textStyle="bold|italic" /><TextViewandroid:id="@+id/text3"android:layout_width="wrap_content"android:layout_height="fill_parent"android:layout_weight="2"android:background="#000000"android:text="Text3"android:textColor="#EA5246"android:textSize="18sp"android:textStyle="bold|italic" /><TextViewandroid:id="@+id/text4"android:layout_width="wrap_content"android:layout_height="fill_parent"android:layout_weight="3"android:background="#00aa00"android:text="Text4"android:textColor="#EA5246"android:textSize="18sp"android:textStyle="bold|italic" /></LinearLayout>

2.表格布局

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"android:id="@+id/TableLayout1"android:layout_width="fill_parent"android:layout_height="fill_parent"android:stretchColumns="0" ><TableRow><TextViewandroid:id="@+id/row1_text0"android:padding="3dip"android:text="row1-text0" /><TextViewandroid:id="@+id/row1_text1"android:padding="3dip"android:text="row1-text1" /></TableRow><TableRow><TextViewandroid:id="@+id/row2_text0"android:padding="3dip"android:text="row2-text0" /><TextViewandroid:id="@+id/row2_text1"android:padding="3dip"android:text="row2-text1" /><TextViewandroid:id="@+id/row2_text3"android:padding="3dip"android:text="row2-text3" /></TableRow><Viewandroid:layout_height="2dip"android:background="#FF909090" /><TableRow><TextViewandroid:id="@+id/row3_text0"android:padding="3dip"android:text="row3-text0" /><TextViewandroid:id="@+id/row3_text1"android:padding="3dip"android:text="row3-text1" /></TableRow></TableLayout> android:stretchColumns="0" //設置第一列為可拉伸列,讓該列填滿這一行所有的剩余空間 android:collapseColumns="0,2" //隱藏第一與第三列 android:shrinkColumns="1" //設置第二個列為可收縮列

3.框架布局

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"android:id="@+id/FrameLayout1"android:layout_width="fill_parent"android:layout_height="fill_parent"android:foreground="@drawable/ic_launcher" ><TextViewandroid:id="@+id/text1"android:layout_width="200dp"android:layout_height="200dp"android:background="#FF6143" /><TextViewandroid:id="@+id/text2"android:layout_width="150dp"android:layout_height="150dp"android:layout_gravity="bottom"android:background="#7BFE00" /><TextViewandroid:id="@+id/text3"android:layout_width="100dp"android:layout_height="100dp"android:background="#FFFF00" /></FrameLayout>

4.相對布局

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"android:id="@+id/RelativeLayout1"android:layout_width="match_parent"android:layout_height="match_parent" ><TextViewandroid:id="@+id/textView1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignParentLeft="true"android:layout_alignParentTop="true"android:text="Enter your name :"android:textSize="20dip" /><EditTextandroid:id="@+id/editText1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignParentLeft="true"android:layout_alignParentRight="true"android:layout_below="@+id/textView1"android:layout_marginTop="16dp"android:ems="10" ><requestFocus /></EditText><Buttonandroid:id="@+id/button1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_below="@+id/editText1"android:layout_toLeftOf="@+id/button2"android:text="Cancel" /><Buttonandroid:id="@+id/button2"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignBaseline="@+id/button1"android:layout_alignBottom="@+id/button1"android:layout_alignParentRight="true"android:layout_marginRight="20dp"android:text="Save" /></RelativeLayout>

5.絕對布局

<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="fill_parent"android:layout_height="fill_parent"android:orientation="vertical" ><Buttonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_x="0px"android:layout_y="0px"android:text="按鈕1" /><Buttonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_x="200dp"android:layout_y="6dp"android:text="按鈕3" /><Buttonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_x="1dp"android:layout_y="142dp"android:text="按鈕2" /><Buttonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_x="199dp"android:layout_y="142dp"android:text="按鈕4" /></AbsoluteLayout>

總結

以上是生活随笔為你收集整理的构建用户界面 Android 应用中一些常用的小部件的全部內容,希望文章能夠幫你解決所遇到的問題。

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

主站蜘蛛池模板: 在线观看1区 | 韩国三级做爰视频 | jzzjzz日本丰满少妇 | 亚洲国产日韩在线一区 | 国产精品三区在线观看 | 国产富婆一级全黄大片 | mm1313亚洲国产精品美女 | v片在线免费观看 | mm1313亚洲国产精品无码试看 | 男人的天堂2019 | 亚洲最大成人在线 | 国产精品日韩精品欧美精品 | 国产小视频免费观看 | 韩国日本美国免费毛片 | 国产大片b站| 国产精品一区二区久久 | 91在线观看免费高清完整版在线观看 | 美女视屏 | 杨贵妃颤抖双乳呻吟求欢小说 | av一级黄色 | 一级黄色短片 | 中文字幕有码在线观看 | 一区三区在线观看 | 欧美视频一区 | 日本一本一道 | 亚洲久久在线 | 欧美18一20男同69gay | 自拍偷自拍亚洲精品播放 | 制服.丝袜.亚洲.中文.综合懂色 | 最新国产拍偷乱偷精品 | 亚洲永久精品视频 | 中日韩精品一区二区三区 | 亚洲熟妇一区二区三区 | 国产成人8x视频一区二区 | 青娱乐91视频| 国产男人的天堂 | 欧美激情精品久久 | 国产亚洲一区二区三区在线观看 | 天堂影视av | 日本少妇bb| 成年人免费观看视频网站 | 一女被多男玩喷潮视频 | 天天爽夜夜爽 | 日韩精品一二 | 午夜黄色一级片 | 国产高清免费观看 | 男女扒开双腿猛进入爽爽免费 | 一本到久久| 韩毛片 | 久久久伊人网 | 亚洲色图在线观看视频 | 国产又粗又硬又黄的视频 | 日日夜夜干 | 国产精品久久中文字幕 | 曰曰操 | 黄色一级视频在线观看 | 亚洲AV无码精品久久一区二区 | 亚洲精品综合 | 国产精品白嫩极品美女 | 国产男女猛烈无遮挡免费观看网站 | 亚洲天堂av网 | 中国少妇av | 亚洲中文无码久久 | 国产欧美精品一区二区色综合 | 免费的黄色的视频 | 狠狠丁香 | 在线黄色av | 日本不卡一区二区三区在线观看 | 国产真实乱在线更新 | 日韩精品一区二区三区色欲av | 日韩欧美卡一卡二 | 国产福利资源在线 | 性盈盈影院中文字幕 | 日本精品久久久久中文字幕 | 国产精品3p视频 | 3d欧美精品动漫xxxx无尽 | 日本一区二区三区网站 | 在线观看亚洲大片短视频 | 国产成人a人亚洲精品无码 在线aa | 精品麻豆 | 日韩欧美成人一区二区三区 | 国产人成一区二区三区影院 | 日韩丰满少妇无码内射 | 寡妇高潮一级视频免费看 | 亚洲精品国产日韩 | 我色综合| 小早川怜子久久精品中文字幕 | 精品天堂 | 久久人久久 | 少妇高潮网站 | 精品成人久久 | 国产热| 精品偷拍一区 | 亚洲av色一区二区三区精品 | 国产一线二线三线在线观看 | 成熟女人毛片www免费版在线 | 国产十八熟妇av成人一区 | 久草aⅴ | 青娱乐青青草 |