Google Glass Card Design for only Image - android

I know that there are some design layouts (for example TEXT, TITLE, COLUMS etc.)
What I would like to show is just a picture from drawable. When I use the TEXT Layout with .addImage, the picture is in background (darker). I tried to use the TITLE Layout, but in this case I also see a black vignette at the bottom.
I would like to screen only a picture. And I'm using the devicedefault theme, because I've also some cards with only text or columns etc.
I tried to use an EMBEDDED Layout with a custom XML file, but the picture is not fullscreen. Is there a simple solution for this problem? Thank you in advance.
Here is also the code, im still having trouble:
private void addImageView(LinearLayout layout) {
ImageView iv = new ImageView(this);
Object drawable;
iv.Drawable(Drawable drawable); //problem here?
iv.setPadding(0, 0, 0, 0);
iv.setAdjustViewBounds(true);
iv.setScaleType(ImageView.ScaleType.CENTER);
}
private void createCards() {
mCards = new ArrayList<CardBuilder>();
mCards.add(new CardBuilder(this, CardBuilder.Layout.TITLE)
.setText("This is TITLE")
.addImage(R.drawable.title)
.setImageLayout( ImageLayout.FULL)); //also problem here?

Please look at this link and I am sure it will help you a lot, I was also using it on Google Glass Card Design.

You can simply set an ImageView as the content of the Activity:
ImageView image = new ImageView(this);
image.setScaleType(ImageView.ScaleType.CENTER_CROP);
image.setImageDrawable(yourDrawable);
// or image.setImageResource(R.drawable.your_image);
// or image.setImageBitmap(yourBitmap);
setContentView(image, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));

Related

Set an image in imageView

I'm pretty new in Android and I am trying to make a Mancala (it's kind of an African game) app. I am looking for a way to update an Image View from one image to another programmatically (for those who are familiar with the game- I want the images of the empty holes to update to images with balls every time the player plays).
I tried to look for an answer but I didn't find one. Here is what I've tried:
imgHome2=(ImageView)findViewById(R.drawable.home0);
You can do same by using Drawable:
private ImageView imageView;
on onCreate()
imageView = (ImageView) findViewById(imageView);
Create new method for set drawable on ImageView.
private void setDrawableOnImageView(Drawable drawable){
imageView.setImageDrawable(drawable);
}
How to call above method:
Drawable drawable = getResources().getDrawable(R.drawable.ic_launcher);
setDrawableOnImageView(drawable);
You can change drawable as your requirement.
in findViewById you should pass an id not a drawable
imgHome2=(ImageView)findViewById(R.id.myimageviewid)
and than you can change the image by
imgHome2.setBackground(R.drawable.home0);

Create and remove image at certain coordinates on android

I have an XML Relative layout, with just a few textviews and buttons on it. But I would like to place an image (or sometimes multiple copies of the image) at different x and Y coordinate which is worked out later on.
Unfortunately I can't seem to figure out how to create the ImageView in android (besides XML) and make it appear at the desired coordinate.
Also it would be great if I could help in making it disappear or removing it at a later stage as well.
You can create a ImageView programmatically with ImageView iv = new ImageView(context); Then you have to set the LayoutParameters for the view. If you plan to add the view to a RelativeLayout you must use RelayiveLayout.LayoutParams. So you can have to do the same as you know from xml: add layout rules. See the documentation.
Then overall something like this:
ImageView iv = new ImageView(context);
RelayiveLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
// TODO set the params
params.addRule(RelativeLayout.ALIGN_PARENT_TOP);
iv.setLayoutParams(params);
relativeLayout.addView(iv);
To hide the imageView you can user imageView.setVisibility(View.GONE)

Android/Monodroid image smaller than imagebutton

I want to create an imagebutton, but the image doesn't fill the imagebutton. The image has the same dimensions as the imagebutton.
The imagebutton has the correct dimension, it seems like the imagebutton has an padding?!
I tried most of the scaletypes.
My code:
ImageButton ib = new ImageButton(Context);
AbsoluteLayout.LayoutParams lp = new AbsoluteLayout.LayoutParams((int)getWidth(3), (int)rowHeight, (int)offsetValue, (int)(offsetRow+row*rowHeight));
Stream bitmap = act.Assets.Open("somefolder/" + name + ".gif");
Bitmap bMap = Android.Graphics.BitmapFactory.DecodeStream(bitmap);
bMap = Bitmap.CreateScaledBitmap(bMap, (int)getWidth(3), (int)rowHeight, false);
ib.SetScaleType(ImageButton.ScaleType.FitXy);
ib.SetAdjustViewBounds(true);
ib.SetImageBitmap(bMap);
bitmap = null;
bMap = null;
ib.LayoutParameters = lp;
layout.AddView(ib);
Yeah it has a padding or something like that, I wanted to create a button in an EditText in order to allow the user to make a password viewable and had the same issue... and haven't found a solution for this until now.
For what you are trying I recomment using an ImageView and make it clickable than you have the same functionality, just like an imagebutton,
Standard 9-patch drawable for ImageButton defined in Android framework has content padding which doesn't allow you to use all space inside the button. To solve this problem, use your own background drawable (set it with android:background="#drawable/..." attribute) or adjust the drawable you set in android:src attribute.
Please read this article for more information on how content padding is defined by 9-patch drawables.

How to center a Imageview on the screen? (with java code)

atm i'm using this code, but this code doesn't works for me, because the code is stretching the Image on the screen, i dont want that, i need that the image uses his real size (200x210)
FrameLayout fl = new FrameLayout(this.getApplicationContext());
splash = new ImageView(getApplicationContext());
splash.setImageResource(R.drawable.logo2);
fl.addView(splash);
fl.setForegroundGravity(Gravity.CENTER);
fl.setBackgroundColor(Color.BLACK);
setContentView(fl);
How to do it without making a giant image that it is using all the screen?
You have to specify scalType if you don't want imageview to stretch your image.
splash.setScaleType(ScaleType.CENTER);
use this properties of ImageView as shown here:
splash.setAdjustViewBounds(true);
and tell me if it is working.

Android - how to add a dynamic image to activity

I currently have an activity that does not have an xml layout file. All items are added when needed. I am not in need to add a image to it and it doesnt seem to do anything...
ImageView iv = new ImageView(this);
iv.setScaleType(ImageView.ScaleType.FIT_CENTER);
Bitmap bm = BitmapFactory.decodeFile(Environment.getExternalStorageDirectory()+"/Pics/Pic_1.jpg");
iv.setImageBitmap(bm);
ll.addView(iv);
The image is in the correct folder...11 at the end is the Linear view i am adding the image view too...am i missing something?
You can use debugger to see if image is loaded correctly.
And have you tried to set layout params on that ImageView. Because in your case it wouldn't take any space (I think). Try something like:
ll.addView(iv, new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
Or use exact sizes instead of LayoutParams.WRAP_CONTENT

Categories

Resources