Android 開發技巧總結(三)

來源:互聯網
上載者:User

標籤:android   style   color   strong   os   width   

1.在介面中按返回鍵判斷某個控制項的可見度,如果可見,則用動畫讓其消失,應用並不退出。

Onkeydown方法中:

if(keyCode == 4){

if(slidingMenu.getVisibility() == View.VISIBLE){

//退出的動畫

AnimationSet animationSet = new AnimationSet(true);

TranslateAnimation animation = new TranslateAnimation(0,-280, 0, 0);

animation.setDuration(500);

animationSet.addAnimation(animation);

slidingMenu.startAnimation(animationSet);

slidingMenu.setVisibility(View.GONE);

return true; //如果控制項在介面是可見的話,按返回鍵讓其消失,應用並不退出

}

}

2.控制介面的延時跳轉

public class WelcomeActivity extends Activity{

private Handler mHandler = new Handler() {

public void handleMessage(android.os.Message msg) {

goMain();

}};

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

        setContentView(R.layout.welcome);

}

@Override

protected void onResume() {

super.onResume();

mHandler.sendEmptyMessageDelayed(0, 3000);

}

/**

 * 跳轉到主介面

 */

private void goMain() {

Intent intent = new Intent(WelcomeActivity.this, MainActivity.class);

startActivity(intent);

this.finish();

}}

3.擷取螢幕寬和高

DisplayMetrics dm = new DisplayMetrics();
                this.getWindowManager().getDefaultDisplay().getMetrics(dm);
                screenWidth = dm.widthPixels;
                screenHeight = dm.heightPixels;

4.private protected public的區別

public
公用,加上這個修飾的類或屬性,可以在同一個包或者別的包裡面訪問

private
私人的,加上這個修飾的類或屬性,只能在同類裡訪問,同包和別的包不能訪問

protected
保護,加上這個修飾的類或屬性,只能在同類和同包訪問,別的包不能訪問

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.