當前位置:首頁 » 動態圖片 » android圖片按鈕繼承哪個類
擴展閱讀
男人難受背影的圖片 2025-05-18 03:56:08
貼瓷板工具有哪些圖片 2025-05-18 03:43:11

android圖片按鈕繼承哪個類

發布時間: 2022-06-20 19:18:15

『壹』 android四大組件繼承哪個父類

Android四組件別activity、service、content provider、broadcast receiver 、android四組件詳解 1、activity (1)Activity通單獨屏幕(窗口) (2)Activity間通Intent進行通信 (3)android應用每Activity都必須要AndroidManifest.xml配置文件聲明否則系統識別執行該Activity 2、service (1)service用於台完用戶指定操作service兩種: (a)started(啟):應用程序組件(activity)調用startService()啟服務服務處於started狀態 (b)bound(綁定):應用程序組件調用bindService()綁定服務服務處於bound狀態 (2)startService()與bindService()區別: (a)started service(啟服務)由其組件調用startService()啟導致服務onStartCommand()調用服務started狀態其命周期與啟組件關並且台限期運行即使啟服務組件已經銷毀服務需要完任務調用stopSelf()停止或者由其組件調用stopService()停止 (b)使用bindService()啟用服務調用者與服務綁定起調用者旦退服務終止求同必須同死特點 (3)發員需要應用程序配置文件聲明全部service使用標簽 (4)Service通位於台運行般需要與用戶交互Service組件沒圖形用戶界面Service組件需要繼承Service基類Service組件通用於其組件提供台服務或監控其組件運行狀態 3、content provider (1)android平台提供Content Provider使應用程序指定數據集提供給其應用程序其應用通ContentResolver類該內容提供者獲取或存入數據 (2)需要應用程序間共享數據才需要內容提供者例通訊錄數據應用程序使用且必須存儲內容提供者處統數據訪問式 (3)ContentProvider實現數據共享ContentProvider用於保存獲取數據並使其所應用程序見同應用程序間共享數據唯式android沒提供所應用共同訪問公共存儲區 (4)發員直接使用ContentProvider類象數通ContentResolver象實現ContentProvider操作 (5)ContentProvider使用URI唯標識其數據集URIcontent://作前綴表示該數據由ContentProvider管理 4、broadcast receiver (1)應用使用外部事件進行濾興趣外部事件(電呼入或者數據中國絡用)進行接收並做響應廣播接收器沒用戶界面啟activity或serice響應收信息或者用NotificationManager通知用戶通知用種式吸引用戶注意力例閃背燈、震、播放聲音等般說狀態欄放持久圖標用戶打並獲取消息 (2)廣播接收者注冊兩種別程序態注冊AndroidManifest文件進行靜態注冊 (3)態注冊廣播接收器特點用注冊Activity關掉廣播失效靜態注冊需擔憂廣播接收器否關閉要設備啟狀態廣播接收器打著說哪怕app本身未啟該app訂閱廣

『貳』 關於android 繼承了BaseAdapter類後的一些問題,我這個程序就是為了實現一個圖片的拖拽,就是Gallery

因為你的getCount()返回的是mImageIds.length為5;
所以 getView(int position, ... )會先後將自動被調用5次。產生5個view。這5個view就是你在Galley里看到的5個view。
第一次調用,position=0.
每二次調用,position=1,
。。。
最後一次,position=4.
只要在你的getView(int position, ... )方法中寫成imageview.setImageResource(mImageIds[position]);
因為每次position不一樣,剛好就把你的五幅圖順序擺放了。

『叄』 android開關按鈕怎麼實現

在Android中,不管什麼樣子的視圖都是繼承自View類,因此我們必須要自定義一個View類,下面看一下代碼實現:

com\mandr\demo\ TestSlipButtonActivity.java
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
public class TestSlipButtonActivity extends Activity {

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

SlipButton mSlipButton=(SlipButton)findViewById(R.id.slipButton);
mSlipButton.setOnChangedListener(new OnChangedListener() {
@Override
public void OnChanged(boolean checkState) {
if(checkState){
Log.d("TestSlipButtonActivity", "checkState = "+checkState);
}else{
Log.d("TestSlipButtonActivity", "checkState = "+checkState);
}
}
});
}
}

//View的核心代碼
public class ToogleButton extends View {
private static final String Tag="ToogleButton";
private int width;
private int height;
private Paint mPaint;

public ToogleButton(Context context) {
super(context);
init();
}

public ToogleButton(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public ToogleButton(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init();
}

private void init(){
Log.d(Tag, "init()");
mPaint = new Paint();
mPaint.setColor(Color.GRAY);
mPaint.setAlpha(255);
mPaint.setAntiAlias(true);
}
@Override
protected void onDraw(Canvas canvas) {
//draw rect
RectF rectF = new RectF();
width = 80;
height = 30;
rectF.set(0, 0, width, height);
canvas.drawRoundRect(rectF, 7, 7, mPaint);
//draw half
mPaint.setColor(Color.BLUE);
RectF tButton = new RectF();
tButton.set(0, 0, width/2, height);
canvas.drawRoundRect(tButton, 7, 7, mPaint);
//draw text
mPaint.setColor(Color.BLACK);
mPaint.setTextSize(23);
mPaint.setTextAlign(Align.CENTER);
mPaint.setTypeface(Typeface.DEFAULT);
canvas.drawText("開", 15, 25, mPaint);
canvas.drawText("關", 57, 25, mPaint);
//draw half
mPaint.setColor(Color.WHITE);
RectF button = new RectF();
button.set(0, 0, width/2, height);
canvas.drawRoundRect(button, 7, 7, mPaint);
super.onDraw(canvas);
}

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
Log.d(Tag, "widthMeasureSpec ="+widthMeasureSpec);
Log.d(Tag, "heightMeasureSpec = "+heightMeasureSpec);
width = MeasureSpec.getSize(widthMeasureSpec);
height = MeasureSpec.getSize(heightMeasureSpec);
Log.d(Tag, "width="+width);
Log.d(Tag, "height="+height);

super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
super.onTouchEvent(event);
if(event.getAction() == MotionEvent.ACTION_DOWN){
int eventX = (int)event.getX();
int eventY = (int)event.getY();
Log.d(Tag, "x = "+eventX+", y ="+eventY);
if(eventX <(width /2)){
Log.d(Tag, "開");
}else{
Log.d(Tag, "關");
}
}

return true;
}
}
測試程序比較簡單,就是把自定義的View組件當作一般的系統View組件使用就可以了,用法一樣,在此我給出一個範例:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
<com.mandr.demo.SlipButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/slipButton"
/>
</LinearLayout>
到此一個精美的按鈕組件就開發完成了,希望對你以後的開發有用。附加了view的全部代碼。

『肆』 android 代碼,一個類不繼承Activity如何使用menu

你可以先讓B繼承Activity實現menu,然後讓其他子類A再繼承實現了按鈕功能的B

『伍』 在android中按鈕共分為幾種

關於Android中View控制項的分類可以分為以下幾類:
1. 文本類:
TextView、EditText、AutoCompleteTextView、MultAutoCompletTextView 、(TextSwitcher) 、(DigitalClock)
ExtractEditText、CheckedTextView、Chronometer

2.按鈕類:
Button、CheckBox、RadioButton(RadioGroup) 、ToggleButton 、(ImageButton ) CompoundButton

2. 縮放按鈕:
ZoomButton、ZoomControls

3. 圖片類:
ImageView、ZoomButton、ImageButton、(ImageSwitcher ) QuickContactBadge

4. 時間控制項:
DigitalClock、AnalogClock、TimePicker、DatePicker

5.進度顯示:
ProgressBar、AbsSeekBar、SeekBar、RatingBar(星星評分)

6.導航: TabHost、TabWidget。

7.視頻媒體:
VideView、MediaController

8.Dialog對話框
CharacherPickerDialog、AlertDialog、DatePickerDialog、ProgressDialog、TimePickerDialog

9. 布局類控制項:
AbsoluteLayout、LinearLayout、RadioGroup 、TableLayout、 TableRow、RelativeLayout、FrameLayout

10.需要適配器的布局類:
AdapterView、AbsListView、GridView、ListView、AbsSpinner、Gallery Spinner

11.滾動條: HorizontalScrollView、ScrollView

12.網頁: WebView

13.動畫: ViewAimator、ViewFilpper、ViewSwitcher、ImageSwitcher、TextSwitcher

『陸』 android五大布局繼承哪個類

所有的控制項和布局 都繼承View這個類

『柒』 android自定義組件應該直接或間接繼承哪個類


1、自定義view需要注意構造函數,所有的xml布局,初始化時構造函數使用的都是(Contextcontext,AttributeSetattrs){兩個參數的。如果沒有該構造函數會報錯。

2、如果有自定義屬性,則需要在當前xml中引入工程包名,否則自定義屬性會報錯

這個問題報錯的願意是第一個,構造函數使用錯誤。增加構造函數就能解決問題。

比如:

publicclassMyViewextendsView{//下面2個構造函數都加上
publicMyView(Contextcontext){
}
publicMyView(Contextcontext,AttributeSetattrs){
super(context,attrs);
}
}

『捌』 android中帶圖標的按鈕(ImageButton)怎麼用

除了Android系統自帶的Button按鈕以外,還提供了帶圖標的按鈕ImageButton
要製作帶圖標的按鈕,首先要在布局文件中定義ImageButton,然後通過setImageDrawable方法來設置要顯示的圖標。
注意:
我們可以在布局文件中就直接設置按鈕的圖標,如
android:src=」@drawable/icon1″
我們也可以在程序中設置自定義圖標
imgbtn3.setImageDrawable(getResources().getDrawable(R.drawable.icon2));
我們還可以使用系統自帶的圖標
imgbtn4.setImageDrawable(getResources().getDrawable(android.R.drawable.sym_call_incoming));
設置完按鈕的圖標後,需要為按鈕設置監聽setOnClickListener,以此捕獲事件並處理
下面的例子講述的是由4個圖標按鈕組成的布局,其中三個按鈕的圖標是自定義的,第四個按鈕的圖標是系統的,當點擊按鈕1的時候,彈出dialog,當點擊按鈕2的時候,點擊確定後,可以將按鈕2的圖標變成按鈕3的圖標,當點擊按鈕3的時候,按鈕3的圖標變成了系統打電話的圖標,點擊按鈕4,顯示一個提示dialog
ImageButtonTest.java源代碼
package org.loulijun.imagebutton;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.TextView;

public class ImageButtonTest extends Activity {
/** Called when the activity is first created. */
TextView textview;
ImageButton imgbtn1;
ImageButton imgbtn2;
ImageButton imgbtn3;
ImageButton imgbtn4;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

textview=(TextView)findViewById(R.id.textview);
//分別取得4個ImageButton對象
imgbtn1=(ImageButton)findViewById(R.id.imagebutton1);
imgbtn2=(ImageButton)findViewById(R.id.imagebutton2);
imgbtn3=(ImageButton)findViewById(R.id.imagebutton3);
imgbtn4=(ImageButton)findViewById(R.id.imagebutton4);

//分別為ImageButton設置圖標
//imgbtn1已經在main.xml布局中設置了圖標,所以就不在這里設置了(設置圖標即可在程序中設置,也可在布局文件中設置)
imgbtn2.setImageDrawable(getResources().getDrawable(R.drawable.icon));//在程序中設置圖標
imgbtn3.setImageDrawable(getResources().getDrawable(R.drawable.icon2));
imgbtn4.setImageDrawable(getResources().getDrawable(android.R.drawable.sym_call_incoming));//設置系統圖標

//下面為各個按鈕設置事件監聽
imgbtn1.setOnClickListener(new Button.OnClickListener()
{
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Dialog dialog=new AlertDialog.Builder(ImageButtonTest.this)
.setTitle("提示")
.setMessage("我是ImageButton1")
.setPositiveButton("確定",new DialogInterface.OnClickListener() {

@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
//相應的處理操作
}
}).create();
dialog.show();
}

});

imgbtn2.setOnClickListener(new Button.OnClickListener()
{
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Dialog dialog=new AlertDialog.Builder(ImageButtonTest.this)
.setTitle("提示")
.setMessage("我是ImageButton2,我要使用ImageButton3的圖標")
.setPositiveButton("確定",new DialogInterface.OnClickListener() {

@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
imgbtn2.setImageDrawable(getResources().getDrawable(R.drawable.icon2));
}
}).create();
dialog.show();
}

});

imgbtn3.setOnClickListener(new Button.OnClickListener()
{
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Dialog dialog=new AlertDialog.Builder(ImageButtonTest.this)
.setTitle("提示")
.setMessage("我是ImageButton3,我想使用系統打電話的圖標")
.setPositiveButton("確定",new DialogInterface.OnClickListener() {

@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
imgbtn3.setImageDrawable(getResources().getDrawable(android.R.drawable.sym_action_call));
}
}).create();
dialog.show();
}

});

imgbtn4.setOnClickListener(new Button.OnClickListener()
{
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Dialog dialog=new AlertDialog.Builder(ImageButtonTest.this)
.setTitle("提示")
.setMessage("我是使用的系統圖標")
.setPositiveButton("確定",new DialogInterface.OnClickListener() {

@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
//相應的處理操作
}
}).create();
dialog.show();
}

});
}
}

布局文件main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:id="@+id/textview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="ImageButton測試案例"
/>
<ImageButton
android:id="@+id/imagebutton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/icon1"
/>
<ImageButton
android:id="@+id/imagebutton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<ImageButton
android:id="@+id/imagebutton3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<ImageButton
android:id="@+id/imagebutton4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>

『玖』 android一般繼承哪幾個類 activity

安卓的界面xml文件是和Activity類綁定的,二者缺一不可,看你的類實現什麼功能,如果是人機交互的,即處理某個界面的的一系列操作的,就得繼承Activity類,你只要記住一點,就是xml文件是需要通過Activity類才能起作用的

『拾』 android 如何繼承Activity類實現雙指縮放、單指拖曳圖片

onTouch方法和onTouchEvent方法。

onTouch方法是View的 OnTouchListener借口中定義的方法。

當一個View綁定了OnTouchLister後,當有touch事件觸發時,就會調用onTouch方法。
(當把手放到View上後,onTouch方法被一遍一遍地被調用)

onTouchEvent方法是override 的Activity的方法。
重新了Activity的onTouchEvent方法後,當屏幕有touch事件時,此方法就會別調用。
(當把手放到Activity上時,onTouchEvent方法就會一遍一遍地被調用)
在一個Activity裡面放一個TextView的實例tv,並且這個tv的屬性設定為 fill_parent
在這種情況下,當手放到屏幕上的時候,首先會是tv響應touch事件,執行onTouch方法。

如果onTouch返回值為true,
表示這個touch事件被onTouch方法處理完畢,不會把touch事件再傳遞給Activity,
也就是說onTouchEvent方法不會被調用。
(當把手放到屏幕上後,onTouch方法被一遍一遍地被調用)

如果onTouch的返回值是false,
表示這個touch事件沒有被tv完全處理,onTouch返回以後,touch事件被傳遞給Activity,
onTouchEvent方法被調用。
(當把手放到屏幕上後,onTouch方法調用一次後,onTouchEvent方法就會一遍一遍地被調用)