2017-08-01 76 views
0

我改變我的按鈕的風格是這樣的:Android的XML屬性編程

RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams)btBroadcast.getLayoutParams(); 
params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); 
params.addRule(RelativeLayout.CENTER_VERTICAL); 
btBroadcast.setLayoutParams(params); 

如何添加上述這四個規則是什麼?

android:layout_marginRight="16dp" 
android:scaleType="centerInside" 
android:layout_width="20" 
android:layout_height="20" 

回答

1
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams)btBroadcast.getLayoutParams(); 
params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); 
params.addRule(RelativeLayout.CENTER_VERTICAL); 
params.height = 10; 
params.width = 20; 
params.rightMargin = 10; 
btBroadcast.setScaleType(ImageView.ScaleType.CENTER); 
btBroadcast.setBackgroundResource(R.drawable.image); 
btBroadcast.requestLayout(); 
+0

生病接受3分鐘這個答案,你知道如何使從繪項目文件夾這一點透明藏漢和圖像? – junikear

+0

在'btBroadcast.setAlpha(0.8F);' –

+0

中加入'alpha'給btn你還可以告訴我如何從drawables文件夾設置背景圖片嗎? – junikear