下面列出了android.widget.RelativeLayout#setBackgroundResource ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private void startEditMode(RecyclerView parent) {
this.isEditMode = true;
int childCount = parent.getChildCount();
for (int i = 0; i < childCount; i++) {
View view = parent.getChildAt(i);
if (view != null) {
ImageView imgEdit = (ImageView) view.findViewById(R.id.edit_tip);
RelativeLayout layout = (RelativeLayout) view.findViewById(R.id.item_group_id);
if (layout != null) {
layout.setBackgroundResource(R.drawable.channel_wall_item_selecter_bg);
}
if (imgEdit != null) {
if (((Integer) imgEdit.getTag()).intValue() == 0) {
imgEdit.setBackgroundResource(2130837812);
} else {
imgEdit.setBackgroundResource(2130837811);
}
imgEdit.setVisibility(0);
}
}
}
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View rootView = LayoutInflater.from(context).inflate(R.layout.adapter_navigation_gridview_item, null);
ImageView iv = (ImageView) rootView.findViewById(R.id.imageView1);
RelativeLayout relativeLayout = (RelativeLayout) rootView.findViewById(R.id.relativeLayout);
TextView txtName = (TextView) rootView.findViewById(R.id.name);
//TextView txtDesc = (TextView) rootView.findViewById(R.id.desc);
ImageInfo imageInfo = imageList.get(position);
iv.setImageResource(imageInfo.imageId);
if (Strings.isEmpty(imageInfo.desc) || "0".equals(imageInfo.desc)) {
txtName.setText(imageInfo.navigation.name);
} else {
txtName.setText(imageInfo.navigation.name + "("+imageInfo.desc+")");
}
relativeLayout.setBackgroundResource(imageInfo.bgId);
relativeLayout.getBackground().setAlpha(225);
return rootView;
}
private void initFaceImageViews(){
int wrapperHeight = screenHeight/5;
LinearLayout.LayoutParams wrapperLayoutParams = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, wrapperHeight);
int imageWrappers[] = {R.id.imageViewWrapper1, R.id.imageViewWrapper2, R.id.imageViewWrapper3, R.id.imageViewWrapper4,
R.id.imageViewWrapper5, R.id.imageViewWrapper6, R.id.imageViewWrapper7,
R.id.imageViewWrapper8, R.id.imageViewWrapper9, R.id.imageViewWrapper10};
int imageViews[] = {R.id.imageView1, R.id.imageView2, R.id.imageView3, R.id.imageView4, R.id.imageView5,
R.id.imageView6, R.id.imageView7, R.id.imageView8, R.id.imageView9, R.id.imageView10};
for(int i = 0; i < imageWrappers.length; i++) {
RelativeLayout wrapper = (RelativeLayout)findViewById(imageWrappers[i]);
wrapper.setBackgroundResource(R.drawable.borders);
wrapper.setLayoutParams(wrapperLayoutParams);
}
for(int i = 0; i < imageViews.length; i++) {
ImageView faceImage = (ImageView)findViewById(imageViews[i]);
faceImage.setPadding(1, 1, 1, 1);
faceImage.setScaleType(ScaleType.FIT_XY);
faceImage.setScaleType(ScaleType.FIT_XY);
faceImage.setLayoutParams(new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
faceImage.setBackgroundResource(R.drawable.borders);
faceImage.setImageResource(R.drawable.icon);
faceImages.add(faceImage);
}
}
public Scroller(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs);
LayoutInflater inflater = LayoutInflater.from(context);
View root = inflater.inflate(R.layout.scroller, this, true);
observableScrollView = (ObservableScrollView) root.findViewById(R.id.scroll_view);
centeredLayout = (RelativeLayout) root.findViewById(R.id.centered_layout);
mMaskImage = (BottomCropImage) root.findViewById(R.id.mask_image);
mImage = (ImageView) root.findViewById(R.id.image);
Drawable unfilledIcon = context.getResources().getDrawable(R.drawable.ic_icon_unfilled);
DisplayMetrics metrics = Resources.getSystem().getDisplayMetrics();
final int width = metrics.widthPixels;
final int height = metrics.heightPixels;
ViewGroup.LayoutParams params = centeredLayout.getLayoutParams();
params.height = ((BitmapDrawable) unfilledIcon).getBitmap().getHeight();
centeredLayout.setLayoutParams(params);
totalHeight = height * SCROLL_VELOCITY;
RelativeLayout relativeLayout = new RelativeLayout(context);
relativeLayout.setLayoutParams(new LayoutParams(width, totalHeight));
relativeLayout.setBackgroundResource(R.drawable.scroller_background);
observableScrollView.addView(relativeLayout);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
if ((savedInstanceState != null) && savedInstanceState.containsKey(CONTENT)) {
mContent = savedInstanceState.getString(CONTENT);
}
TextView text = new TextView(getActivity());
text.setGravity(Gravity.CENTER);
text.setText(mContent);
text.setTextSize(20 * getResources().getDisplayMetrics().density);
RelativeLayout layout = new RelativeLayout(getActivity());
layout.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
layout.setGravity(Gravity.CENTER);
RelativeLayout alert = new RelativeLayout(getActivity());
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
params.leftMargin = 20;
params.rightMargin = 20;
params.addRule(RelativeLayout.CENTER_HORIZONTAL);
params.addRule(RelativeLayout.CENTER_IN_PARENT);
alert.setLayoutParams(params);
alert.setBackgroundResource(R.drawable.red_back);
alert.setPadding(30, 0, 30, 0);
alert.addView(text);
layout.addView(alert);
return layout;
}
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (D) Log.d(TAG, "onActivityResult " + resultCode);
switch (requestCode) {
case REQUEST_CONNECT_DEVICE:
// When DeviceListActivity returns with a device to connect
if (resultCode == Activity.RESULT_OK) {
// Get the device MAC address
String address = data.getExtras()
.getString(BluetoothActivity.EXTRA_DEVICE_ADDRESS);
// Get the BLuetoothDevice object
BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(address);
// Attempt to connect to the device
mBluetoothService.connect(device);
}
break;
case REQUEST_ENABLE_BT:
// When the request to enable Bluetooth returns
if (resultCode == Activity.RESULT_OK) {
// Bluetooth is now enabled, so set up a chat session
blueToothSetup();
} else {
// User did not enable Bluetooth or an error occured
Log.d(TAG, "BT not enabled");
/*Toast.makeText(this, R.string.bt_not_enabled_leaving, Toast.LENGTH_SHORT).show();*/
showSnackBar(getResources().getString(R.string.bt_not_enabled));
finish();
}
break;
case REQUEST_CAMERA:
if (resultCode == Activity.RESULT_OK) {
Bitmap bmp = (Bitmap) data.getExtras().get("data");
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.JPEG, 100, stream);
byte[] img = stream.toByteArray();
dataImage = Base64.encodeToString(img, Base64.DEFAULT);
//Toast.makeText(this, dataImage, Toast.LENGTH_SHORT).show();
Drawable roundedImage = new RoundImage(bmp);
RelativeLayout relativeLayout = (RelativeLayout) findViewById(R.id.enroll_relative_layout);
relativeLayout.setBackgroundResource(R.drawable.white_circle);
enrollImage.setScaleType(ImageView.ScaleType.FIT_XY);
enrollImage.setImageDrawable(roundedImage);
isCaptureImage = true;
} else {
Log.d(TAG, "Image not captured");
showSnackBar("Image not captured");
}
break;
}
}