欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

Android自定義控件-創(chuàng)新互聯(lián)

android自定義按鈕

成都網(wǎng)站建設(shè)哪家好,找創(chuàng)新互聯(lián)公司!專注于網(wǎng)頁設(shè)計(jì)、重慶網(wǎng)站建設(shè)公司、微信開發(fā)、微信平臺(tái)小程序開發(fā)、集團(tuán)成都企業(yè)網(wǎng)站定制等服務(wù)項(xiàng)目。核心團(tuán)隊(duì)均擁有互聯(lián)網(wǎng)行業(yè)多年經(jīng)驗(yàn),服務(wù)眾多知名企業(yè)客戶;涵蓋的客戶類型包括:自拌料攪拌車等眾多領(lǐng)域,積累了大量豐富的經(jīng)驗(yàn),同時(shí)也獲得了客戶的一致稱揚(yáng)!

1》定義按鈕布局文件

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      androidAndroid自定義控件rientation="horizontal"
      android:layout_gravity="center"
      android:layout_width="wrap_content"
      android:layout_height="fill_parent"
      >
  <ImageView
        android:id="@+id/iconMoney"
        android:layout_width="25dp"
        android:layout_height="fill_parent"
        >
  </ImageView>
  <TextView
        android:id="@+id/numMeoney"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:gravity="center"
        android:text="4444"
        android:textSize="20dp"
        android:layout_marginTop="0dp"
        android:layout_marginBottom="3dp"
        android:layout_marginLeft="8dp"
        >
  </TextView>
  <ImageView
        android:layout_marginLeft="5dp"
        android:id="@+id/iconAdd"
        android:layout_width="25dp"
        android:layout_height="fill_parent"
        >
  </ImageView>
</LinearLayout>

2》繼承布局文件

package com.widget;

import android.content.Context;
import android.graphics.Bitmap;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.dreamplanegames.R;

public class MoneyView extends LinearLayout {

  private ImageView iconMoney;
  private TextView textView;

  private ImageView Addmoney;

  public MoneyView(Context context,AttributeSet attributeSet) {
      super(context, attributeSet);
      LayoutInflater.from(context).inflate(R.layout.money, this,true);//指定布局

      this.iconMoney = (ImageView)findViewById(R.id.iconMoney);
      this.textView = (TextView)findViewById(R.id.numMeoney);
      this.Addmoney=(ImageView)findViewById(R.id.iconAdd);

      this.setClickable(true);//可以點(diǎn)擊
      this.setFocusable(true);
  }

//設(shè)置控件內(nèi)容
  public void setText(String text) {
      this.textView.setText(text);
  }

  public void setTextColor(int color) {
      this.textView.setTextColor(color);
  }

  public void setTextSize(float size) {
      this.textView.setTextSize(size);
  }

  public void setImg(Bitmap img1,Bitmap img2) {
      this.iconMoney.setImageBitmap(img1);
      this.Addmoney.setImageBitmap(img2);
      //this.yes.setImageBitmap(img2);
  }

}

3》控件的調(diào)用

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  androidAndroid自定義控件rientation="horizontal"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  >
  <ImageView android:id="@+id/mainMenuImage"
      android:src="@drawable/xk_bg2"
      android:scaleType="fitXY"
      android:layout_width="match_parent"
      android:layout_height="match_parent">
  </ImageView>
//調(diào)用自定義控件
  <com.widget.MoneyView--------------------類名
        android:layout_width="wrap_content"
        android:layout_height="30dp"
        android:id="@+id/btnMoney"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginTop="20dp"
        android:layout_marginLeft="20dp"
        >
  </com.widget.MoneyView>

</RelativeLayout>

4》到相應(yīng)的activity調(diào)用
public class SFMainMenu extends Activity implements View.OnClickListener
{
  public MoneyView moneyview;
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      //設(shè)置全屏
      getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
          WindowManager.LayoutParams.FLAG_FULLSCREEN);
      //去除應(yīng)用程序標(biāo)題
      this.requestWindowFeature(Window.FEATURE_NO_TITLE);
      //設(shè)置豎屏
      setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
      setContentView(R.layout.main);

//獲取自定義按鈕
      moneyview=(MoneyView)findViewById(R.id.btnMoney);

//調(diào)用自定義控件的函數(shù)設(shè)置控件內(nèi)容
      moneyview.setImg(BitmapFactory.decodeResource(getResources(), R.drawable.money),BitmapFactory.decodeResource(getResources(), R.drawable.add));
      moneyview.setText(""+myPointBalance);

      //自定義按鈕響應(yīng)事件
      moneyview.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
          // TODO Auto-generated method stub

        }
      });

}
  //返回鍵
  @Override
  public void onBackPressed() {
      super.onBackPressed();

  }

}

另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。

網(wǎng)站名稱:Android自定義控件-創(chuàng)新互聯(lián)
鏈接地址:http://chinadenli.net/article44/dggghe.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站收錄、全網(wǎng)營銷推廣營銷型網(wǎng)站建設(shè)、Google網(wǎng)站建設(shè)網(wǎng)站改版

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

網(wǎng)站優(yōu)化排名