Transparent overlay in imageview in a tablelayout - android

I have a tablelayout with two rows each consisting of two imageview. I want to achieve result as below. I have tried few solutions mentioned in stackoverflow but somehow I have not found a way to achieve this. Each imageview is looks as below
<ImageView
android:id="#+id/imageViewY"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#drawable/cell_border"
android:clickable="true"
android:padding="2dp"
android:src="#drawable/letter_y" />
If you have any idea or solution to achieve this , i would like to request for your help. Thanks in advance.

use transparent color #11000000 as background of imageview
Here 11 is a Transparency Value of color 000000(means Black color)
and you can set alpha programatically or through xml for setting transparency
now If Set Alpha You said deprecated and don't want to take risk by using this then just set color of image view
i just explain how to handle 1st imageview's click
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(v==imageview1){
//set lighter dark layer on click of image 1 and reset fully transparent layer on other image
imageview1.setBackgroundColor(Color.parseColor("#11000000"));
imageview2.setBackgroundColor(Color.parseColor("#00000000"));
imageview3.setBackgroundColor(Color.parseColor("#00000000"));
imageview4.setBackgroundColor(Color.parseColor("#00000000"));
}
}

Related

setCompoundDrawablePadding() to zero

i want to Put the image on text in the button.
I want to set the spacing between text and images to zero.
In addition, a button with a size of 200 dp x 200 dp
I want the images and text to be laid out in the same vertical padding.
Please help me.
Button b = findViewById(R.id.button);
Drawable d = getResources().getDrawable(R.drawable.ic_launcher_background,getTheme());
b.setCompoundDrawablesWithIntrinsicBounds(null,d,null,null);
b.setCompoundDrawablePadding(0);
b.setText("good");
b.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(MainActivity.this, "hellow", Toast.LENGTH_SHORT).show();
}
});
There's an alternative way of doing this and it can prove easier.
Instead of using a Button and trying to use an drawable with it, have you considered using a TextView and add a drawable to it? It can be done within your XML and you can add padding. Something like,
<TextView
android:id="#+id/my_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="#style/TextAppearance.AppCompat.Button"
android:textColor="#color/text_secondary_dark"
android:drawablePadding="8dp"
android:drawableTop="#drawable/my_icon"
tools:drawableTint="#000"/>
As you can see, you can add a drawable, its padding, its tint etc.

ImageButton not always clickable on the first click

I have a number of ImageButtons in a layout. The image resources are 32x32 px. They all have the same attributes:
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/ibButton1"
android:clickable="true"
android:focusable="false"
android:focusableInTouchMode="false"
android:layout_weight="0"
android:src="#drawable/not_selected"
android:layout_gravity="center_vertical"
android:background="#null"/>
In my fragment, I'm doing:
final ImageButton button1 = (ImageButton)view.findViewById(R.id.ibButton1);
button1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
isSelected = !isSelected;
if (isSelected ) {
button1.setImageResource(R.drawable.selected);
}
else {
button1.setImageResource(R.drawable.not_selected);
}
}
});
However, most times I need to click over 5 times on the button for it to register the click.
Should I need to increase the image size or is there a better way to listen to clicks? Should I use onClick attribute instead?
Provide some padding to increase the Tap area.
android:padding="10dp"
Perhaps, the size of the image is too small(as #Shoeb Siddique said) to get touch event on the image. You can increase the padding or size of image to improve the probability to touch the image.
It seems to me , you don`t need an ImageButton, but a ToggleButton with to states.
http://developer.android.com/guide/topics/ui/controls/togglebutton.html
and please remove android:clickable="true" , it is not needed, because it is a button, which mean, it is true by default. If it would be an TextView, it would needed.
Extract Image With Touch zone I Mean Transparent Background
for Eg : the Give Image is 86 * 70 px So When Ever User touches round that Transparent background 86* 70px you can fire event

How do I partially gray out an image when pressed?

I have an image that I use as a button. It is an ImageView within a RelativeLayout. The RelativeLayout is the View that receives the touch events. While touched, I want to partially gray out the image as feedback. How do I do this?
The best way I can think of is to place another View with a black background on top of the ImageView and style it normally 100% transparent, but only 50% transparent when touched. Is there a way to style the RelativeLayout or ImageView directly without using an additional View?
Thanks in advance...
One way you could do it would be to add an onclick method for the ImageView and set a tag for it once it's grayed out and a ColorFilter to gray the view. Then you can un-gray it (provided you want the gray out to be toggled) when clicked again. Here's an example:
Add this to the xml:
<ImageView
...
android:onClick="grayOut"/>
Then in the Activity or View class
public void grayOut(View view) {
// if not grayed
if(view.getTag() != "grayed") {
view.setColorFilter(Color.argb(150,200,200,200));
view.setTag("grayed");
} else {
view.setColorFilter(null);
view.setTag("");
}
}
Use a color filter with a transparent grey color on the view when touched and remove it when you want to remove the grey color. It will be imageView.setColorFilter(transparent grey color); When you want to remove it just set the color filter to null.

How to make horizontal Listview Transparent

I have a custom horizontal listview ,what i want to make is transparent the background for horizontal listview,
i have added the following code too
android:background="#00000000"
android:cacheColorHint="#00000000"
AND
android:background="#android:color/transparent"
android:cacheColorHint="#android:color/transparent"
I have used something like this..
public void setCacheColorHint(int transparent) {
// TODO Auto-generated method stub
}
could any body help me ,#thanks!!
Are the items populating the list supposed to be transparent?
If so you must make sure that their background is transparent.
Oh, and BTW #android:color/transparent == #00000000 so it doesn't really matter which you use.
You should be using this
android:background="#android:color/transparent"
android:cacheColorHint="#android:color/transparent"
Edit:- Try to set the setCacheColorHint(00000000) of the ListView. You need not create a method yourself. ListView already has that.

android image button

How can i create a button with no text and an image centered horizontally ?
I don't want to use an ImageButton because I want to define a different backgound image
You just use an ImageButton and make the background whatever you want and set the icon as the src.
<ImageButton
android:id="#+id/ImageButton01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/album_icon"
android:background="#drawable/round_button" />
just use a Button with android:drawableRight properties like this:
<Button android:id="#+id/btnNovaCompra" android:layout_width="wrap_content"
android:text="#string/btn_novaCompra"
android:gravity="center"
android:drawableRight="#drawable/shoppingcart"
android:layout_height="wrap_content"/>
You can just set the onClick of an ImageView and also set it to be clickable, Or set the drawableBottom property of a regular button.
ImageView iv = (ImageView)findViewById(R.id.ImageView01);
iv.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
}
});
You can use the button :
1 - make the text empty
2 - set the background for it
+3 - you can use the selector to more useful and nice button
About the imagebutton you can set the image source and the background the same picture and it must be (*.png) when you do it you can make any design for the button
and for more beauty button use the selector //just Google it ;)

Categories

Resources