代碼中設置圖片資源:
setbackground//可以是drawable文件下的,也可以是color文件夾下的
settextColor//只能是colors文件夾下的,不能使drawable下的(其實使用也無所謂),但是規範還是要遵守下比較好
代碼中設置佈局文件 寬度和高度:
LinearLayout.LayoutParams timeParams = (LayoutParams)ll_Layout.getLayoutParams()
timeparams.width = width;
timeparams.height = height;
LayoutParams layoutParams = new WindowManager.LayoutParams();
<span style="color:#3366ff;"> </span> android:text="小米遙控器\n1.0版本"
android:gravity="center_horizontal"
android:maxLines="2"
備註:文本換行加\n,然後結合最多顯示幾行maxLines使用,換行後要居中使用gravity
重點是“1.0版本如何在第二行居中”
關於popupwindow設置背景色:
#00000000這個顏色就是透明的
android:startOffset="200"//設置延遲執行時間
private void showPop()
{
Resources resources = getBaseContext().getResources();
Drawable d = resources.getDrawable(Color.BLACK);
View view = this.getLayoutInflater().inflate(R.layout.upload, null);
PopupWindow pop = new MyPopupwindow(view, LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT, this);
pop.setBackgroundDrawable(d);
pop.showAtLocation(findViewById(R.id.webInfo), Gravity.CENTER, 0, 0);
}
關於位移動畫:
Translate動畫是非常好理解,就是定義一個開始的位置和一個結束位置,定義移動時間,然後就能自動產生移動動畫
關於isVisiable()
一般的view判斷是否可見用view.isShown() 也可以用view.getVisiable() == view.setVisiable(View.VISIABLE)
只有fragment可以用fragment.isVisiable();判斷是否可見
想把這個LinearLayout寬度設置成爲FILL_PARENT,源碼如下:
LinearLayout checkboxLinearLayout = (LinearLayout) getLayoutInflater().inflate(R.layout.checkboxdoitem, null);
LayoutParams params= (LayoutParams) checkboxLinearLayout.getLayoutParams();
params.width=LayoutParams.FILL_PARENT;
checkboxLinearLayout.setLayoutParams(params);
本文由NantiJey原創總結,如需轉載請標明出處 :http://blog.csdn.net/jss4j/article/details/43988437