在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 教程/ Android/ Android ImageButton
Android 應用組件
使用布局文件自定義Android組件
Android通知
Android主題示例
Android JetPlayer實例
Android MediaPlayer(多媒體播放)
Android AbsoluteLayout
Android FrameLayout
Android Gestures/手勢
Android AutoCompleteTextView(自動完成)實例
Android 資源組織和訪問
Android ListView
Android GridView
Android數(shù)據(jù)備份
Android撥打電話
Android發(fā)送短信/SMS
Android ProgressDialog
SimpleCursorAdapter
Android發(fā)送電子郵件
Android Activity
Android TextView
Android事件處理
Android TableLayout
Android加載Spinner
Android內(nèi)容提供者
Android自定義字體
Android Service
Android CheckBox
Android Intent過濾器
Android LinearLayout
Android登錄實例
Android RadioButton
Android樣式和主題
Android自定義組件及屬性
Android UI控件
Android Animation(動畫)實例
Android Camera(攝像頭)
Android ToggleButton
Android Clipboard(復制/剪貼板)
Android音頻捕獲(錄音)
發(fā)布Android應用
Android Alertdialog(警告對話框)
Android圖片效果
Android內(nèi)部存儲
Android基于位置服務
Android RadioGroup
Android AutoCompleteTextView
Android Bluetooth(藍牙)實例
Android RelativeLayout
Android最佳實踐
Android本地化
Android自定義組件
Android教程
Android 架構
Android UI布局
Android Button
Android Hello World示例
Android音頻管理器實例
ArrayAdapter
Android拖放
Android碎片/片段
Android圖片切換
Android JSON解析器
Android開發(fā)環(huán)境搭建
Android Spinner
Android樣式示例
使用活動代碼自定義Android組件
Android ImageButton
Android EditText
Android廣播接收器

Android ImageButton

ImageButton是一個AbsoluteLayout布局,它能夠指定其子視圖的確切位置。顯示的圖像(而不是文本),可由用戶按下或點擊一個按鈕。

ImageButton 屬性

以下是相關 ImageButton 控件的重要屬性。可以檢查Android官方文檔的屬性和相關方法的完整列表,可以用它來改變這些屬性在運行時。

繼承自類android.widget.ImageView:

屬性 描述
android:adjustViewBounds 設置為true,如果想調(diào)整ImageView其邊界,以保持其繪制的高寬比
android:baseline 這是偏移此視圖內(nèi)部基線
android:baselineAlignBottom 如果為true,則圖像視圖會基于其底部邊緣基線對齊
android:cropToPadding 如果為true,圖像將被裁剪以適合其填充之內(nèi)
android:src 這將設置一個可繪制的 ImageView 內(nèi)容

從 android.view.View 類繼承:

屬性 描述
android:background 這是一個可拉伸使用來做背景
android:contentDescription 定義文本簡要描述視圖內(nèi)容
android:id 對此視圖提供一個標識符名稱
android:onClick 在本視圖的上下文視圖被點擊時調(diào)用的方法的名稱
android:visibility 控制視圖的初始可視性

示例

這個例子將通過簡單的步驟,來展示如何創(chuàng)建自己的Android應用使用線性布局及ImageButton。

步驟 描述
1 使用Android Studio創(chuàng)建Android應用程序,其工程名稱為:ImageButtonDemo
2 修改src/MainActivity.java文件,添加一個click事件
2 修改res/layout/activity_main.xml文件的默認內(nèi)容包括Android的UI控件
3 在res/values/strings.xml文件中定義所需的常量
4 運行該應用程序啟動Android模擬器并驗證應用程序所運行的結果

以下是主活動文件 src/com.yiibai.imagebuttondemo/MainActivity.java 的內(nèi)容。這個文件可以包括每個生命周期的基本方法。

package com.yiibai.imagebuttondemo;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.widget.Toast;

public class MainActivity extends Activity {
	
	ImageButton imgButton;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);

          addListenerOnButton();
        }

	private void addListenerOnButton() {
		
          imgButton = (ImageButton) findViewById
          (R.id.imageButton1);

          imgButton.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
              Toast.makeText(MainActivity.this,"ImageButton 
              Clicked : yiibai.com", 
              Toast.LENGTH_SHORT).show();
            }
          });		
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
         /* Inflate the menu; this adds items to the action bar            
         if it is present */
         getMenuInflater().inflate(R.menu.main, menu);
         return true;
     }
}

下面是 res/layout/activity_main.xml 文件的內(nèi)容:

<RelativeLayout 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:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/example_imagebutton" />

    <ImageButton
        android:id="@+id/imageButton1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignRight="@+id/textView1"
        android:layout_below="@+id/textView1"
        android:layout_marginRight="35dp"