It is necessary to impose on the image obtained from the Internet, the image of the youtube button. How can I do that?
4 answers
You can use the ImageView feature by which for this widget you can specify both the content and the background in the form of an image to combine them.
<ImageView android:id="@+id/imageView" android:src="@drawable/icon" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/thumb" android:adjustViewBounds="true" /> Here
icon - the image of any icon (must have a transparent background)
thumb - image of the picture.
The adjustViewBounds parameter must be set in order for the image to fit into the dimensions of the widget.
If the icon requires some kind of padding or other positioning, you can use something like a LayerList and similar Drawadle Resources that provide the ability to set the position for the image. For example, move the icon 50dp left and down.
Create a resource: res / drawable / icon.xml
<?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/icon" android:left="50dp" android:top="50dp"/> </layer-list> For example, put them in FrameLayout
The first image from the Internet, your youtube button image second and in the end it will be superimposed on the first.
- The images I own should be displayed in the GridView. That's the whole difficulty for me, I can't understand how
FrameLayoutcan be displayed in a single cell - kalugin1912
Try using the LayerDrawable class, which when creating an object using the constructor parameter, takes an array from the Drawable you need:
LayerDrawable layerDrawable = new LayerDrawable(drawableList); Solved the problem in this way
items.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/items" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <ImageView android:id="@+id/main_img" android:layout_width="wrap_content" android:layout_height="wrap_content" android:scaleType="fitCenter"/> <ImageView android:id="@+id/mini_img" android:layout_width="24dp" android:layout_height="24dp" android:adjustViewBounds="true" android:layout_centerInParent="true" android:scaleType="centerCrop" /> </RelativeLayout> getView () in GridViewImageAdapter.java
@Override public View getView(int position, View convertView, ViewGroup parent) { View grid; if (convertView == null) { grid = new View(activity); LayoutInflater inflater = (LayoutInflater) activity.getSystemService( Context.LAYOUT_INFLATER_SERVICE ); grid = inflater.inflate(R.layout.items, parent, false); } else { grid = convertView; } ImageView imgMain=(ImageView) grid.findViewById(R.id.main_img); ImageView imgMini= (ImageView) grid.findViewById(R.id.mini_img); AppConstants.setImage(activity,position,imgMain,imgMini,AppConstants.mThumbIds); imgMain.setScaleType(ImageView.ScaleType.CENTER_CROP); imgMain.setLayoutParams(new RelativeLayout.LayoutParams(imageWidth, imageWidth)); imgMain.setOnClickListener(new OnImageClickListener(position)); if(AppConstants.mThumbIds[position].getIsVideo()) { imgMini.setPadding(0, 0, 8, 0); imgMini.setScaleType(ImageView.ScaleType.FIT_CENTER); imgMini.setImageBitmap(BitmapFactory.decodeResource( activity.getResources(), R.drawable.youtube16)); } return grid; }
RelativeLayoutor make customImageView- ermak0ff