Android (eclipse) image button vs background image - java

I'm trying to figure out which is best to use.
I'm trying to develop a simple game and designing the starting activity. to start the game I plan to have a start button.
I want to use a custom design though.
My question is, should I use an ImageButton (which I believe is an imported image that you can click on, or a textview with android:background="#drawable/imageName".
Both seem to allow onClick if I'm not mistaken so what's the pros and or one over the other?
Hope this isn't duplicate question, all I found was info on how to upload images which I don't need. Just need to know advantages to using one versus the other.
also, Does onclick for textview apply to background or only text?

I think imagebutton maybe better.
because you must have a click effect for feedback . if you use background for the image ,you have to write a selector.xml for change the click and unclick effects.
so, i think imagebutton may be better.

You can use android:src="#drawable/imageName"
So that the image will be perfect fit. Also you can use
android:scaleType="fitCenter"
android:adjustViewBounds="true"
If you are using TextView then your background may not be good

From : Difference between a clickable ImageView and ImageButton
There's no differences, except default style. ImageButton has a non-null background by default.
Also, ImageButton.onSetAlpha() method always returns false, scaleType is set to center and it's always inflated as focusable.
Here's ImageButton's default style:
<style name="Widget.ImageButton">
<item name="android:focusable">true</item>
<item name="android:clickable">true</item>
<item name="android:scaleType">center</item>
<item name="android:background">#android:drawable/btn_default</item>
</style>

Related

Fixed background while switching layouts

I got my application uploaded and I see that despite I have the same background image on all my layouts.
if I switch, the layout moves according to the animation.
Is there a way for me to set a fixed background for all my layouts?
Does it matter that I finish(); every layout before I switch to the next one?
Setting the same background to all the layouts doesn't make it fixed (it moves)
neither does creating a style like :
<style name="AppTheme.FullBackground" parent="AppTheme">
<item name="android:background">#mipmap/background</item>
</style>
and adding :
android:theme="#style/AppTheme.FullBackground"
to the manifest.
Any ideas?
If you are using all activities in your app then change all activities to fragment and just use one activity with your required image as background.
Then use just this activity for all the fragments in your app. This will not move your background image during navigating to different screens(fragments)

How to control the width or the visibility of an activity

I'm using this awesome library Dragger to add drag features to my activity, but is there a way to limit the width of the activity when it shows up or dragged..!? I don't want it to fill the entire screen..! kinda like the drawer navigation menu (see the pic below).
I was thinking of Dialog Activity, but it seems to be concerned with dialogs only and won't allow filling the other 3 sides or I not fully understand it..!
Any help?
Activity is not a view, so it does not have a size. Its' layout views do however.
You can try changing their sizes. Or, as it is an animation lib, you can try modifying existing or adding your own animations where views change sizes when moving. You can modify this param:
<item name="android:windowAnimationStyle">#null</item>
This might help you.

How to create this Setting Layout in android?

I want to create a settting UI like this in android:
Questions:
How to create the layout? I believe it's a Vertical LinearLayout containing some of TextView with Divider set, is that right?
How to create sub-textview? (see the image above)
How to create a checkbox which aligned at right? (again, see the image above)
Look at the image above, the "Keypress popup" can be clicked and it will show up a dialog. How to create a clickable TextView? I have tried giving android:onClick on the TextView, but nothing happened when I clicked the TextView.
PreferenceActivity will help you to implement all these very easily. Go through this and this tutorials.
PreferenceFragment should be used post Honeycomb.

How do I create this Transparent Dialog/Canvas for Android?

I'm a beginner Android developer and I'm making my first app. I'd like to make a simple view that is overlayed on the map with a semi-transparent background. This is what it would hopefully look like:
As you can see, one of these dialogs/windows has a simple integer displayed and the other will have a rendered graph/chart.
What would be the best way to go about making this? A dialog? The problem with that might be that I would for the user to be able to work with the mapview below while this is displayed. And I'm not sure if a simple transparent rectangular canvas is the right way to get this done.
Any suggestions/ideas would be much appreciated. Thanks so much.
two ways to go
-Make it a FrameLayout so add MapFragment first then add a Linearlayout with orientation horizontal and make gravity top and translucent background,so it will be displayed on top of map, and it will also involve the elements inside,
-Instead of FrameLayout make it a RelativeLayout and the same process as above.
-Make the overlay as seperate Activity(which is the worst case scenario)
Sample code for overlay can be like this
<LinearLayout
....
android:divider=".." // some drawable or color whatever you want
android:showDividers="middle"
android:orientation="horizontal"
android:background="a000">
<TextView
....
android:value="58"/>
<com.example.custom.view
..../>
</LinearLayout>
I think you can use a RelativeLayout on the top of the MapFragment, with a black background and some opacity (for that you can use a drawable).
Then, on the RelativeLayout you can add other controls like TextView and ImageView
I don't recommand you to use a Dialog, since it sounds like it's not corresponding to your needs.

How to show that ImageButton is pressed?

How to show that ImageButton is pressed if i add image to it like this:
Drawable testPic = getResources().getDrawable(R.drawable.test_pic);
button.setImageDrawable( testPic );
And make transparent background so that there would be just image:
button.setBackgroundColor(Color.TRANSPARENT);
So when i press image button i don't see that it is pressed. I want that image would be highlighted or something when it is pressed.
Also every my button is created dynamically by code and i don't know what image would be and how many button there are.
So any ideas ?
Thanks.
you should use a selector for choosing all the different appearances of a UI element, including an ImageButton.
first comes the state_Pressed=true which means what does it look like when pressed. after that comes the regular which is the normal state of the button.
I think you should use State List for that...
You have to change Image at run time. You can achieve these with the help of xml file.
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="false" android:drawable="#drawable/category_listing_bg_img" />
<item android:state_pressed="true" android:drawable="#drawable/category_listing_bg_img_pressed" />
</selector>
Copy this xml to your drawable folder

Categories