android動態控制組件的位置、大小和新的動畫,android動態

來源:互聯網
上載者:User

android動態控制組件的位置、大小和新的動畫,android動態
一、動態設定組件的位置其中view是需要改變位置的控制項,top是需要設制的位置;private static void setLayoutX(View view,int top) {//複製view的width、height、margin的值產生margin對象  MarginLayoutParams margin=new MarginLayoutParams(view.getLayoutParams());//設定新的邊距  margin.setMargins(margin.leftMargin+350,top,margin.rightMargin,margin.bottomMargin);//把新的邊距產生layoutParams對象  RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(margin);//設制view的新的位置  view.setLayoutParams(layoutParams); } 二、動態設定組件的大小和動畫/**  *   * @param view 需要設定的組件  * @param height 需要設定的高度  * @param width 需要設定的寬度  * @param animation 需要設定的動畫  */private static void setLayoutScale(View view,int height,int width,LayoutAnimationController.AnimationParameters animation) {  RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(view.getLayoutParams());  layoutParams.height=height;  layoutParams.width=width;  layoutParams.layoutAnimationParameters=animation;  view.setLayoutParams(layoutParams); }
android控制項怎隨著手機螢幕大小不同而動態改變位置與大小

weight就是給比例啊,所有的weight加起來就是總的大小
 
android 動態產生控制項,怎設定控制項的大小

首先,你這個button被包含在哪個父控制項中,假定為LinearLayout,變數是mLinear
其次,30dip在代碼中要換成像素。

結果:

Button button = new Button(this);
int px = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
30, getResources().getDisplayMetrics());
button.setLayoutParams(new LinearLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, px));
// 如果父視窗是FrameLayout就寫FrameLayout.LayoutParams
mLinear.addView(button);
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.